(www-display-object-desc): Change URL of HNG card image from
[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 .list .tooltip:hover .tooltiptext {
131     visibility: visible;
132 }
133 -->
134 </style>
135
136 <script
137  src=\"http://hng.chise.org/openseadragon/openseadragon.min.js\"></script>
138
139 <title>EsT %s = %s</title>
140 </head>\n"
141                   genre
142                   (decode-uri-string uri-object 'utf-8-mcs-er))
143           'utf-8-mcs-er))
144         (princ "<body>\n"))
145       (when (eq genre 'character)
146         (dolist (feature (char-feature-property '$object 'additional-features))
147           (mount-char-attribute-table
148            (char-feature-name-at-domain feature '$rev=latest))))
149       (princ
150        (if simple
151            (format
152             (if est-hide-cgi-mode
153                 "<div style=\"text-align:right;\">
154 <a href=\"../../edit/view.cgi?%s=%s\">
155 <input type=\"submit\" value=\"Edit\" />
156 </a>\n"
157               "<div style=\"text-align:right;\">
158 <a href=\"edit/view.cgi?%s=%s\">
159 <input type=\"submit\" value=\"Edit\" />
160 </a>\n")
161             genre rdf-uri-object)
162          (format
163           "<div style=\"text-align:right;\">
164 <a href=\"../view/%s/%s\">
165 <input type=\"submit\" value=\"Simple\" />
166 </a>\n"
167           genre
168           (if (string-match ":" uri-object)
169               (concat
170                (est-uri-encode-feature-name-body
171                 (substring uri-object 0 (match-beginning 0)))
172                "="
173                (est-uri-encode-feature-name-body
174                 (substring uri-object (match-end 0))))))))
175       (princ
176        (format "<input type=\"submit\" value=\"New Account\" />
177 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
178 <input type=\"submit\" value=\"RDF\" />
179 </a>%s
180 </div>
181 <hr />\n"
182                genre rdf-uri-object
183                (if (eq genre 'character)
184                    (format "
185 <a href=\"/est/view/%s/%s/data.json\">
186 <input type=\"submit\" value=\"JSON\" />
187 </a>\n"
188                            genre rdf-uri-object)
189                  "")))
190       (when (setq parents (www-get-feature-value object '<-denotational))
191         (princ (format "<p>%s %s</p>\n<hr>\n"
192                        (www-format-value-as-char-list parents)
193                        (www-format-feature-name '->denotational lang))))
194       (when (setq parents (www-get-feature-value object '<-subsumptive))
195         (princ (format "<p>%s %s</p>\n<hr>\n"
196                        (www-format-value-as-char-list parents)
197                        (www-format-feature-name '->subsumptive lang))))
198       (when (eq genre 'character)
199         (setq GlyphWiki-id (char-GlyphWiki-id object)))
200       (cond
201        ((eq genre 'image-resource)
202         (princ
203          (if (setq ret (concord-object-get object '=location@iiif))
204              (if (setq base-image
205                        (car (concord-object-get object '<-image-segment)))
206                  (format "<a href=\"%s...$.zoom-xywh=%d,%d,%d,%d\"
207 ><img alt=\"%s\" src=\"%s\" /></a>"
208                          (www-uri-encode-object base-image)
209                          (concord-object-get object 'image-offset-x)
210                          (concord-object-get object 'image-offset-y)
211                          (concord-object-get object 'image-width)
212                          (concord-object-get object 'image-height)
213                          ret ret)
214                (if (and image-selection
215                         (string-match "\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)" image-selection))
216                    (progn
217                      (setq x (string-to-int (match-string 1 image-selection))
218                            y (string-to-int (match-string 2 image-selection))
219                            w (string-to-int (match-string 3 image-selection))
220                            h (string-to-int (match-string 4 image-selection)))
221                      (setq width (float
222                                   (concord-object-get object 'image-width)))
223                      ;; (setq height (float
224                      ;;               (concord-object-get object 'image-height)))
225                      (format "<div id=\"openseadragon1\"
226  style=\"width: 800px; height: 600px;\"></div>
227
228 <script type=\"text/javascript\">
229     var viewer;
230     viewer = OpenSeadragon({
231         id: \"openseadragon1\",
232         prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
233         preserveViewport:   true,
234         visibilityRatio:    1,
235         minZoomLevel:       1,
236         defaultZoomLevel:   1,
237         sequenceMode:       true,
238         tileSources:   [ \"%s/info.json\" ]
239     });
240     viewer.addHandler('open', function () {
241       var newBounds = new OpenSeadragon.Rect( %f, %f, %f, %f, 0 );
242       viewer.viewport.fitBounds(newBounds, true);
243       viewer.viewport.applyConstraints();
244     });
245 </script>
246 "
247                            ret
248                            (/ x width)
249                            (/ y width)
250                            (/ w width)
251                            (/ h width)
252                            ))
253                  (format "<div id=\"openseadragon1\"
254  style=\"width: 800px; height: 600px;\"></div>
255
256 <script type=\"text/javascript\">
257     OpenSeadragon({
258         id: \"openseadragon1\",
259         prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
260         preserveViewport:   true,
261         visibilityRatio:    1,
262         minZoomLevel:       1,
263         defaultZoomLevel:   1,
264         sequenceMode:       true,
265         tileSources:   [ \"%s/info.json\" ]
266     });
267 </script>
268 "
269                          ret)))
270            (setq ret (concord-object-get object '=location))
271            (format "<img alt=\"%s\" src=\"%s\" />"
272                    ret ret)))
273         )
274        ((and (eq genre 'glyph-image)
275              (setq image-cobj
276                    (car (concord-object-get object '->image-resource))))
277         (if (and (setq ret (concord-object-get image-cobj '=location@iiif))
278                  (setq base-image
279                        (car (concord-object-get image-cobj '<-image-segment))))
280             (princ
281              (format "<a href=\"../image-resource/%s...$.zoom-xywh=%d,%d,%d,%d\"
282 ><img alt=\"%s\" src=\"%s\" /></a>"
283                      (www-uri-encode-object base-image)
284                      (concord-object-get image-cobj 'image-offset-x)
285                      (concord-object-get image-cobj 'image-offset-y)
286                      (concord-object-get image-cobj 'image-width)
287                      (concord-object-get image-cobj 'image-height)
288                      ret ret))
289           (setq ret (concord-object-get image-cobj '=location))
290           (princ (format "<img alt=\"%s\" src=\"%s\" />"
291                          ret ret)))
292         )
293        ((and (eq genre 'hng-card)
294              (setq ret (concord-object-get object '=hng-card))
295              (setq ret (symbol-name ret))
296              (string-match "\\([0-9]+\\)-\\([0-9]+\\)" ret))
297         (princ
298          (format
299           "<img alt=\"HNG-card:%s\"
300 src=\"http://hng.chise.org/images/HNG/%03d/card/%04d.jpg\"
301 style=\"height: 480px;\" />"
302           ret
303           (string-to-int (match-string 1 ret))
304           (string-to-int (match-string 2 ret))))
305         )
306        (t
307         (setq ret (www-format-encode-string
308                    (est-format-object object 'readable)))
309         (when (string-match
310                "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)[a-z]?\"" ret)
311           (setq HNG-card-id
312                 (intern
313                  (format "%d-%d"
314                          (string-to-int (match-string 1 ret))
315                          (string-to-int (match-string 2 ret)))))
316           (setq HNG-card
317                 (format "hng-card/rep.id=%s" HNG-card-id)))
318         (princ
319          (format "<h%d>%s%s</h%d>\n"
320                  level
321                  (cond
322                   (uri-feature-name
323                    (format "<a href=\"%s\">%s</a>"
324                            ;; (if est-hide-cgi-mode
325                            ;;     "<a href=\"../%s\">%s</a>"
326                            ;;   "<a href=\"%s\">%s</a>")
327                            (www-uri-make-object-url object uri-object)
328                            ret)
329                    )
330                   (HNG-card
331                    (format
332                     "<a href=\"../%s\">%s</a>"
333                     HNG-card ret)
334                    )
335                   (t ret))
336                  (if GlyphWiki-id
337                      (format
338                       " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
339                       GlyphWiki-id
340                       GlyphWiki-id GlyphWiki-id)
341                    "")
342                  level))
343         ))
344       (if (> level 1)
345           (princ "<ul>"))
346       (when feature-name-to-edit
347         (princ "<form action=\"set.cgi\" method=\"GET\">\n")
348         (princ
349          (encode-coding-string
350           (format "<p>(%s : <input type=\"text\" name=\"%s\"
351 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
352 "
353                   genre genre
354                   (decode-uri-string uri-object 'utf-8-mcs-er))
355           'utf-8-mcs-er)))
356       (when (and HNG-card-id
357                  (eq genre 'character)
358                  (setq HNG-card-cobj
359                        (concord-decode-object
360                         '=id HNG-card-id
361                         'hng-card)))
362         (put-char-attribute object 'sources@HNG/card (list HNG-card-cobj))
363         (if (setq ret (concord-object-get
364                        HNG-card-cobj
365                        '->glyph-image@zinbun/takuhon))
366             (put-char-attribute object 'sources@zinbun/takuhon ret))
367         )
368       (setq object-spec
369             (cond
370              (uri-feature-name
371               (setq feature-name-to-display
372                     (www-uri-decode-feature-name uri-feature-name))
373               (setq est-eval-list-feature-items-limit nil)
374               (list
375                (cons feature-name-to-display
376                      (if (eq genre 'character)
377                          (get-char-attribute object feature-name-to-display)
378                        (concord-object-get object feature-name-to-display)))))
379              (t
380               (if (eq genre 'character)
381                   (char-attribute-alist object)
382                 (concord-object-spec object)))))
383       (when feature-name-to-edit
384         (unless (assq base-name-to-edit object-spec)
385           (setq object-spec (cons (cons base-name-to-edit nil)
386                                   object-spec))))
387       (dolist (cell (sort object-spec
388                           (lambda (a b)
389                             (char-attribute-name<
390                              (char-feature-name-sans-versions (car a))
391                              (char-feature-name-sans-versions (car b))))))
392         (setq logical-feature (char-feature-name-sans-versions (car cell)))
393         (unless (memq logical-feature chise-wiki-displayed-features)
394           (push logical-feature chise-wiki-displayed-features)
395           (cond
396            ((and feature-name-to-edit
397                  (eq (car cell) feature-name-to-edit))
398             (www-edit-display-feature-input-box
399              object feature-name-to-edit editing-format)
400             )
401            (t
402             (princ
403              (if (= level 1)
404                  "<div class=\"feature\" style=\"line-height:150%\">\n"
405                "<li>\n"))
406             (princ
407              (www-format-eval-list
408               (www-feature-format logical-feature)
409               object
410               logical-feature ; (car cell)
411               lang uri-object
412               nil simple))
413             (unless simple
414               (princ
415                (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
416 ><input type=\"submit\" value=\"note\" /></a>"
417                        chise-wiki-edit-url
418                        genre
419                        (www-format-encode-string uri-object)
420                        (www-format-encode-string
421                         (www-uri-encode-feature-name
422                          (intern (format "%s*note"
423                                          logical-feature ; (car cell)
424                                          )))))))
425             (when (and feature-name-to-edit
426                        (eq base-name-to-edit (car cell)) metadata-name-to-edit)
427               (princ "<ul>\n")
428               (princ "<li>")
429               (www-edit-display-feature-input-box
430                object feature-name-to-edit editing-format)
431               (princ "</li>")
432               (princ "</ul>"))
433             (princ
434              (if (= level 1)
435                  "</div>\n"
436                "<li>\n"))
437             ))
438           ))
439       (princ
440        (if (= level 1)
441            "<p>\n"
442          "<li>\n"))
443       (when feature-name-to-edit
444         (princ "</form>\n"))
445       (unless simple
446         (princ
447          (format "<a href=\"%s?%s=%s\"
448 ><input type=\"submit\" value=\"add feature\" /></a>
449 "
450                  chise-wiki-add-url
451                  genre
452                  (www-format-encode-string uri-object))))
453       (princ
454        (if (= level 1)
455            "<p>\n"
456          "<li>\n"))
457       (when (eq genre 'character)
458         (princ
459          "<form action=\"http://www.chise.org/ids-find\">\n")
460         (princ
461          (www-format-encode-string
462           (est-format-object object)
463           ;; (if (eq genre 'character)
464           ;;     (format "%c" object)
465           ;;   (format "%s" (concord-object-id object)))
466           ))
467         (princ
468          (format
469           " <input type=\"text\" name=\"components\"
470 size=\"30\" maxlength=\"30\" value=\"%s\" />"
471           (encode-coding-string
472            (est-format-object object)
473            ;; (if (eq genre 'character)
474            ;;     (char-to-string object)
475            ;;   (format "%s" (concord-object-id object)))
476            'utf-8-jp-er)))
477         (princ
478          (www-format-encode-string
479           "を\u542Bむ\u6F22\u5B57を\u63A2す"))
480         (princ " <input type=\"submit\" value=\"search\" />\n")
481         (princ "</form>\n")
482
483         (princ
484          "<form action=\"http://www.chise.org/hng-ids-find\">\n")
485         (princ
486          (www-format-encode-string
487           (est-format-object object)
488           ;; (if (eq genre 'character)
489           ;;     (format "%c" object)
490           ;;   (format "%s" (concord-object-id object)))
491           ))
492         (princ
493          (format
494           " <input type=\"text\" name=\"components\"
495 size=\"30\" maxlength=\"30\" value=\"%s\" />"
496           (encode-coding-string
497            (est-format-object object)
498            ;; (if (eq genre 'character)
499            ;;     (char-to-string object)
500            ;;   (format "%s" (concord-object-id object)))
501            'utf-8-jp-er)))
502         (princ
503          (www-format-encode-string
504           "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
505         (princ " <input type=\"submit\" value=\"search\" />\n")
506         (princ "</form>\n")
507         )
508       (princ
509        (if (= level 1)
510            "</p>\n"
511          "<li>\n"))
512       )))
513
514 (defun www-display-feature-desc (uri-feature-name genre uri-object
515                                                   &optional lang simple)
516   (let ((rdf-uri-object (if est-hide-cgi-mode
517                             (if (string-match "=" uri-object)
518                                 (concat
519                                  (est-uri-decode-feature-name-body
520                                   (substring uri-object 0 (match-beginning 0)))
521                                  ":"
522                                  (est-uri-decode-feature-name-body
523                                   (substring uri-object (match-end 0))))
524                               uri-object)))
525         (feature-name (www-uri-decode-feature-name uri-feature-name))
526         (name@lang (intern (format "name@%s" lang))))
527     (princ
528      (encode-coding-string
529       (format "<head>
530 <title>EsT feature: %s</title>
531 </head>\n"
532               feature-name)
533       'utf-8-mcs-er))
534     (princ "<body>\n")
535     (princ
536      (if simple
537          (format
538           (if est-hide-cgi-mode
539               "<div style=\"text-align:right;\">
540 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
541 <input type=\"submit\" value=\"Edit\" />
542 </a>
543 <input type=\"submit\" value=\"New Account\" />
544 </div>
545 <hr />\n"
546             "<div style=\"text-align:right;\">
547 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
548 <input type=\"submit\" value=\"Edit\" />
549 </a>
550 <input type=\"submit\" value=\"New Account\" />
551 </div>
552 <hr />\n")
553           uri-feature-name genre rdf-uri-object)
554        (format
555         "<div style=\"text-align:right;\">
556 <a href=\"../view/feature/%s&%s/%s\">
557 <input type=\"submit\" value=\"Simple\" />
558 </a>
559 </div>
560 <hr />\n"
561         uri-feature-name genre uri-object)))
562     (princ
563      (format "<h1>%s</h1>\n"
564              (www-format-encode-string
565               (symbol-name feature-name))))
566     (princ (format "<p>name : %s "
567                    (or (www-format-feature-name feature-name) "")))
568     (unless simple
569       (princ
570        (format
571         " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
572         chise-wiki-edit-url
573         uri-feature-name
574         genre
575         uri-object))
576       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
577     (princ "</p>\n")
578     (when lang
579       (princ "<p>")
580       (princ
581        (www-format-encode-string
582         (format "%s : %s"
583                 name@lang
584                 (or (char-feature-property feature-name name@lang) ""))))
585       (unless simple
586         (princ
587          (format
588           " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
589           chise-wiki-edit-url
590           uri-feature-name
591           name@lang
592           genre
593           uri-object))
594         (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
595       (princ "</p>\n"))
596     (www-html-display-paragraph
597      (format "type : %s"
598              (or (www-feature-type feature-name)
599                  ;; (char-feature-property feature-name 'type)
600                  'generic)))
601     (princ (format "<p>value-format : %s "
602                    (www-format-value
603                     nil 'value-format 
604                     (or (www-feature-value-format feature-name)
605                         'default)
606                     'default
607                     'without-tags)
608                    ))
609     (unless simple
610       (princ
611        (format
612         " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
613 >"
614         chise-wiki-edit-url
615         uri-feature-name
616         genre
617         uri-object))
618       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
619     (princ "</p>\n")
620
621     (princ (format "<p>value-presentation-format : %s "
622                    (www-format-value
623                     nil 'value-presentation-format 
624                     (or (www-feature-value-format feature-name)
625                         'default)
626                     'default
627                     'without-tags)
628                    ))
629     (unless simple
630       (princ
631        (format
632         " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
633 >"
634         chise-wiki-edit-url
635         uri-feature-name
636         genre
637         uri-object))
638       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
639     (princ "</p>\n")
640
641     (princ "<p>format : ")
642     (www-html-display-text
643      (decode-coding-string
644       (www-xml-format-list
645        (www-feature-format feature-name))
646       'utf-8-mcs-er))
647     (unless simple
648       (princ
649        (format
650         " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
651 >"
652         chise-wiki-edit-url
653         uri-feature-name
654         genre
655         uri-object))
656       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
657     (princ "</p>\n")
658     
659     (www-html-display-paragraph
660      (format "description : %s"
661              (or (decode-coding-string
662                   (char-feature-property feature-name 'description)
663                   'utf-8-mcs-er)
664                  "")))
665     (when lang
666       (www-html-display-paragraph
667        (format "description@%s : %s"
668                lang
669                (or (char-feature-property
670                     feature-name
671                     (intern (format "description@%s" lang)))
672                    ""))))
673     ))
674   
675 (defun www-batch-view ()
676   (setq terminal-coding-system 'binary)
677   (condition-case err
678       (let* ((target (pop command-line-args-left))
679              (user (pop command-line-args-left))
680              (accept-language (pop command-line-args-left))
681              (mode (intern (pop command-line-args-left)))
682              (lang
683               (intern
684                (car (split-string
685                      (car (split-string
686                            (car (split-string accept-language ","))
687                            ";"))
688                      "-"))))
689              ret genre)
690         (princ "Content-Type: text/html; charset=UTF-8
691
692 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
693             \"http://www.w3.org/TR/html4/loose.dtd\">
694 <html lang=\"ja\">
695 ")
696         (cond
697          ((stringp target)
698           (when (string-match "^char=\\(&[^&;]+;\\)" target)
699             (setq ret (match-end 0))
700             (setq target
701                   (concat "char="
702                           (www-uri-encode-object
703                            (www-uri-decode-object
704                             'character (match-string 1 target)))
705                           (substring target ret))))
706           (setq target
707                 (mapcar (lambda (cell)
708                           (if (string-match "=" cell)
709                               (progn
710                                 (setq genre (substring cell 0 (match-beginning 0))
711                                       ret (substring cell (match-end 0)))
712                                 (cons
713                                  (intern
714                                   (decode-uri-string genre 'utf-8-mcs-er))
715                                  ret))
716                             (list (decode-uri-string cell 'utf-8-mcs-er))))
717                         (split-string target "&")))
718           (setq ret (car target))
719           (cond ((eq (car ret) 'char)
720                  (www-display-object-desc
721                   'character (cdr ret) (cdr (assq 'feature target))
722                   nil
723                   lang nil
724                   (eq mode 'simple))
725                  )
726                 ((eq (car ret) 'feature)
727                  (www-display-feature-desc
728                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
729                   (car (nth 1 target))
730                   (cdr (nth 1 target))
731                   lang
732                   (eq mode 'simple))
733                  )
734                 (t
735                  (www-display-object-desc
736                   (car ret) (cdr ret) (cdr (assq 'feature target))
737                   nil
738                   lang nil
739                   (eq mode 'simple))
740                  ))
741           ))
742         (princ "\n<hr>\n")
743         (princ (format "mode=%S\n" mode))
744         (princ (format "user=%s\n" user))
745         ;; (princ (format "local user=%s\n" (user-login-name)))
746         (princ (format "lang=%S\n" lang))
747         (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
748         ;; (princ " CHISE ")
749         ;; (princ xemacs-chise-version)
750         (princ "
751 </body>
752 </html>")
753         )
754     (error nil
755            (princ (format "%S" err)))
756     ))
757
758 (defun www-batch-view-smart ()
759   (setq debug-on-error t)
760   (setq terminal-coding-system 'binary)
761   (condition-case err
762       (let* ((est-hide-cgi-mode t)
763              (target (pop command-line-args-left))
764              (user (pop command-line-args-left))
765              (accept-language (pop command-line-args-left))
766              (mode (intern (pop command-line-args-left)))
767              (lang
768               (intern
769                (car (split-string
770                      (car (split-string
771                            (car (split-string accept-language ","))
772                            ";"))
773                      "-"))))
774              ret genre feature obj-url json obj)
775         (cond
776          ((stringp target)
777           (when (string-match "/data\\.json$" target)
778             (setq json t
779                   target (substring target 0 (match-beginning 0))))
780           (when (string-match "^char/\\(&[^&;]+;\\)" target)
781             (setq ret (match-end 0))
782             (setq target
783                   (concat "char/"
784                           (www-uri-encode-object
785                            (www-uri-decode-object
786                             'character (match-string 1 target)))
787                           (substring target ret))))
788           (setq target
789                 (mapcar
790                  (lambda (cell)
791                    (if (string-match "/" cell)
792                        (progn
793                          (setq genre (substring cell 0 (match-beginning 0))
794                                ret (substring cell (match-end 0)))
795                          (cons
796                           (intern (decode-uri-string genre 'utf-8-mcs-er))
797                           (cond
798                            ((string-match "/feature=" ret)
799                             (list (substring ret 0 (match-beginning 0))
800                                   (substring ret (match-end 0)))
801                             )
802                            ((string-match "...$.zoom-xywh=" ret)
803                             (list (substring ret 0 (match-beginning 0))
804                                   nil
805                                   (substring ret (match-end 0)))
806                             )
807                            (t
808                             (list ret)))))
809                      (list (decode-uri-string cell 'utf-8-mcs-er)))
810                    ;; (setq ret (split-string cell "/"))
811                    ;; (cons (intern
812                    ;;        (decode-uri-string (car ret) 'utf-8-mcs-er))
813                    ;;       (cdr ret))
814                    )
815                  (split-string target "&")))
816           (setq ret (car target))
817           (if json
818               (princ "Content-Type: application/json; charset=UTF-8
819
820 ")
821             (princ "Content-Type: text/html; charset=UTF-8
822
823 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
824             \"http://www.w3.org/TR/html4/loose.dtd\">
825 <html lang=\"ja\">
826 ")
827             )
828           ;; (princ (format "<p>%S, %S, %S</p>"
829           ;;                (car ret)(nth 1 ret)(nth 2 ret)))
830           ;; (princ (format "// %S %S\n" ret json))
831           (cond ((or (eq (car ret) 'char)
832                      (eq (car ret) 'character))
833                  (if (and json
834                           (setq obj (www-uri-decode-object
835                                      (car ret)(nth 1 ret)))
836                           (characterp obj))
837                      (with-temp-buffer
838                        ;; (princ (encode-coding-string
839                        ;;         (format "// %S\n" obj)
840                        ;;         char-db-file-coding-system))
841                        (char-db-json-char-data-with-variant obj 'printable)
842                        (encode-coding-region
843                         (point-min)(point-max)
844                         char-db-file-coding-system)
845                        (princ (buffer-string))
846                        )
847                    (www-display-object-desc
848                     'character (nth 1 ret) (nth 2 ret)
849                     nil
850                     lang nil
851                     (eq mode 'simple)))
852                  )
853                 ((eq (car ret) 'feature)
854                  (www-display-feature-desc
855                   (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
856                   (car (nth 1 target))
857                   (nth 1 (nth 1 target))
858                   lang
859                   (eq mode 'simple))
860                  )
861                 ;; ((eq (car ret) 'image-resource)
862                 ;; ;;  (cond
863                 ;; ;;   ((string-match "^\\.iiif=" (nth 1 ret))
864                 ;; ;;    (setq obj-url (decode-uri-string
865                 ;; ;;                   (substring (nth 1 ret) (match-end 0))
866                 ;; ;;                   'utf-8-mcs-er))
867                 ;; ;;    (setq obj (concord-images-add-iiif obj-url))
868                 ;; ;;    (www-display-object-desc
869                 ;; ;;     'image-resource
870                 ;; ;;     (www-uri-encode-object obj)
871                 ;; ;;     (nth 2 ret)
872                 ;; ;;     lang nil
873                 ;; ;;     (eq mode 'simple))
874                 ;; ;;    )
875                 ;; ;;   (t
876                 ;;  (princ (nth 1 ret))
877                 ;;  (www-display-object-desc
878                 ;;   'image-resource (nth 1 ret) (nth 2 ret)
879                 ;;   lang nil
880                 ;;   (eq mode 'simple))
881                 ;; ;;    ))
882                 ;;  )
883                 (t
884                  (www-display-object-desc
885                   (car ret) (nth 1 ret) (nth 2 ret)
886                   (nth 3 ret)
887                   lang nil
888                   (eq mode 'simple))
889                  ))
890           ))
891         (unless json
892           (princ "\n<hr>\n")
893           (princ (format "mode=%S\n" mode))
894           (princ (format "user=%s\n" user))
895           ;; (princ (format "local user=%s\n" (user-login-name)))
896           (princ (format "lang=%S\n" lang))
897           (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
898           ;; (princ " CHISE ")
899           ;; (princ xemacs-chise-version)
900           (princ "
901 </body>
902 </html>")
903           )
904         )
905     (error nil
906            (princ (format "%S" err)))
907     ))
908
909 (provide 'cwiki-view)