OSDN Git Service

v0.15
[cosmic/source.git] / browse.php
1 <?php
2
3 // ファイルブラウザ
4
5 include_once('./config/site.inc.php');
6
7 // とりあえず/抜いとけば安全?
8 $request__ix = $my_cgi->check_request('ix','/^[^\/]+$/','');
9
10 if ($request__ix == '') {
11
12         // ディレクトリインデックスを出力
13
14         $dirs = array();
15
16         $files = scandir(PATH_COMIC);
17         foreach ($files as $one) {
18                 if (is_dir(PATH_COMIC.'/'.$one) && $one!='.' && $one!='..') {
19                         $dirs[get_dir_index($one)][] = $one;
20                 }
21         }
22
23         $comic = '';
24         $index = array();
25         $idx = 0;
26         foreach ($dirs as $var => $val) {
27                 $index[] = '<a href="#'.$idx.'">'.$var.'</a>';
28                 $series = '';
29                 foreach ($val as $one) {
30                         $hash = md5($one);
31                         file_put_contents(PATH_CACHE_IX.'/'.$hash.CACHE_IX_EXT_DIR,$one);
32                         $series .= '<li><a href="./browse.php?ix='.$hash.'">'.htmlspecialchars($one).'</a></li>';
33                 }
34                 $comic .= '<a id="'.$idx.'"></a><h3>'.htmlspecialchars($var).'</h3>';
35                 $comic .= '<ul class="series_list">'.$series.'</ul>';
36                 $idx++;
37         }
38
39         $my_html->set_value('indexlist',implode('|',$index));
40         $my_html->set_value('comiclist',$comic);
41
42 } else {
43
44         // ファイルリストを出力
45
46         $dir = file_get_contents(PATH_CACHE_IX.'/'.$request__ix.CACHE_IX_EXT_DIR);
47         $files = scandir(PATH_COMIC.'/'.$dir);
48
49         $html  = '<a href="./browse.php">&crarr;戻る</a>';
50         $html .= '<h3>'.htmlspecialchars($dir).'</h3>';
51         $html .= '<ul class="comic_list">';
52         foreach ($files as $one) {
53                 if (preg_match('/.+\.zip$/usi',$one)) {
54                         $path = $dir.'/'.$one;
55                         $hash = md5($path);
56                         file_put_contents(PATH_CACHE_IX.'/'.$hash.CACHE_IX_EXT_ZIP,$path);
57
58                         // ブックマークリストを作成する
59                         $bookmark = '';
60                         if (file_exists(PATH_CACHE_IX.'/'.$hash.CACHE_IX_EXT_CX)) {
61                                 $cx = file_get_contents(PATH_CACHE_IX.'/'.$hash.CACHE_IX_EXT_CX);
62                                 $mark = array();
63                                 $page = array();
64                                 foreach (glob(PATH_CACHE_CX.'/'.$cx.str_replace('?','*',CACHE_CX_EXT_MARK)) as $path_to_mark) {
65                                         $a_mark = unserialize(file_get_contents($path_to_mark));
66                                         $mark[] = $a_mark;
67                                         $page[] = $a_mark['pg'];
68                                 }
69                                 if (count($mark)>0) {
70                                         array_multisort($page, SORT_ASC, $mark);
71                                         foreach ($mark as $a_mark) {
72                                                 $bookmark .=
73                                                         '<a href="./viewer.php?ix='.urlencode($hash).
74                                                         '&amp;pg='.$a_mark['pg'].
75                                                         '&amp;re='.urlencode('./browse.php?ix='.$request__ix).
76                                                         '" title="'.htmlspecialchars('P.'.$a_mark['pg'].' '.htmlspecialchars($a_mark['comment'])).
77                                                         '">&para;</a><sup>'.$a_mark['pg'].'</sup>'
78                                                 ;
79                                         }
80                                 }
81                         }
82                         if ($bookmark!='') {
83                                 $bookmark = '<div class="bookmark_list">'.$bookmark.'</div>';
84                         }
85
86                         $title = mb_substr($one,0,mb_strlen($one)-4);
87                         $html .= '<li><a href="./viewer.php?ix='.urlencode($hash).'&amp;re='.urlencode('./browse.php?ix='.$request__ix).'">'.htmlspecialchars($title).'</a>'.$bookmark.'</li>';
88                 }
89         }
90         $html .= '</ul>';
91
92         $my_html->set_value('comiclist',$html);
93 }
94
95 $my_html->apply_template('browse.html',html::REMOVE_UNDEF_TAGS,html::OUTPUT_HTML);
96
97
98
99 // ディレクトリ名から索引を求める
100 function get_dir_index($name) {
101         global $config__dir_index;
102
103         $ret = '';
104
105         $f = mb_substr($name,0,1);
106         foreach ($config__dir_index as $var => $val) {
107                 if (mb_strpos($val,$f) !== false) {
108                         $ret = $var;
109                         break;
110                 }
111                 if ($val == '') {
112                         $ret = $var;
113                 }
114         }
115
116         return $ret;
117 }
118
119
120 ?>