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