-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
490 lines (402 loc) · 20.4 KB
/
Copy pathindex.php
File metadata and controls
490 lines (402 loc) · 20.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<?php
//動画のディレクトリ
$movie = "Videos/実験/AV1";
//サイトタイトル
$SiteTitle = "ワイの動画";
//httpを使用するかhttpsを使用するか指定
#$protocol = "http";
//テンプレートのディレクトリ
$template = "template";
//デフォルトサムネイル
//$DefaultThumb = "./thumb.jpg";
//サムネイル用フォント
$font = "./GenShinGothic-Medium.ttf";
//テンプレートファイル
$TemplateFile['index'] = "index_template.html";
$TemplateFile['menu'] = "menu_template.html";
$TemplateFile['breadcrumbs'] = "breadcrumbs_template.html";
$TemplateFile['subnav'] = "subnav_template.html";
$TemplateFile['contents'] = "contents_template.html";
$TemplateFile['episode'] = "episode_template.html";
//パラメータをセット
$param['Category'] = $_GET['category'];
$param['Series'] = $_GET['series'];
$param['Episode'] = $_GET['episode'];
#$param['ServerURL'] = $protocol."://".$_SERVER["HTTP_HOST"]."/";
$param['ServerURL'] = "./";
//トップページ
if( is_null($param['Category']) && is_null($param['Series']) && is_null($param['Episode']) ){
$CategoryList = category_pickup( "./".$movie )[0];
$ThumbnailURL = category_pickup( "./".$movie)[1];
$param['menu'] = menu_output($param, $CategoryList, $template, $TemplateFile['menu']);
$param['Breadcrumbs'] = breadcrumbs_output( $param, $param['Category'], $param['Series'], $param['Episode'], $template, $TemplateFile['breadcrumbs'] );
$ContentsList = category_pickup( "./".$movie )[0];
$param['ContentsList'] = contents_output($param, $ContentsList, $ThumbnailURL, $template, $TemplateFile['contents']);
$param['PageTitle'] = $SiteTitle;
$TemplateFileLocation = $template."/".$TemplateFile['index'];
echo template_engin($TemplateFileLocation, $param);
}
//シリーズ一覧ページ
else if ( $param['Category'] != NULL && is_null($param['Series']) && is_null($param['Episode']) ){
$CategoryList = category_pickup( "./".$movie )[0];
$param['menu'] = menu_output($param, $CategoryList, $template, $TemplateFile['menu']);
$param['Breadcrumbs'] = breadcrumbs_output( $param, $param['Category'], $param['Series'], $param['Episode'], $template, $TemplateFile['breadcrumbs'] );
$SeriesList = series_pickup( "./".$movie, $param['Category'] )[0];
$ThumbnailURL = series_pickup( "./".$movie, $param['Category'] )[1];
$param['ContentsList'] = contents_output($param, $SeriesList, $ThumbnailURL, $template, $TemplateFile['contents']);
$param['PageTitle'] = htmlspecialchars ( $param['Category']." | ".$SiteTitle );
$TemplateFileLocation = $template."/".$TemplateFile['index'];
echo template_engin($TemplateFileLocation, $param);
}
//エピソード一覧ページ
else if ( $param['Category'] != NULL && $param['Series'] != NULL && is_null($param['Episode']) ){
$CategoryList = category_pickup( "./".$movie )[0];
$param['menu'] = menu_output($param, $CategoryList, $template, $TemplateFile['menu']);
$param['Breadcrumbs'] = breadcrumbs_output( $param, $param['Category'], $param['Series'], $param['Episode'], $template, $TemplateFile['breadcrumbs'] );
$EpisodeList = episode_pickup( "./".$movie, $param['Category'], $param['Series'] )[0];
$EpisodeList = preg_replace( '/\.[^.]*$/', '', $EpisodeList );
$ThumbnailURL = episode_pickup( "./".$movie, $param['Category'], $param['Series'] )[2];
$param['ContentsList'] = contents_output($param, $EpisodeList, $ThumbnailURL, $template, $TemplateFile['contents']);
$param['PageTitle'] = htmlspecialchars ( $param['Category']." | ".$param['Series']." | ".$SiteTitle );
$TemplateFileLocation = $template."/".$TemplateFile['index'];
echo template_engin($TemplateFileLocation, $param);
}
//動画視聴ページ
else if ( $param['Category'] != NULL && $param['Series'] != NULL && $param['Episode'] != NULL ){
$param['Category'] = htmlspecialchars_decode( $param['Category'] );
$param['Series'] = htmlspecialchars_decode( $param['Series'] );
$param['Episode'] = htmlspecialchars_decode( $param['Episode'] );
$EpisodeList = episode_pickup( "./".$movie, $param['Category'], $param['Series'] );
$EpisodeList[0] = preg_replace( '/\.[^.]*$/', '', $EpisodeList[0] );
$i = 0;
foreach ( $EpisodeList[0] as $value ){
if ( $value == $param['Episode'] ){
$param['Extension'] = $EpisodeList[1][$i];
$param['ThumbnailURL'] = $EpisodeList[2][$i];
break;
}
$i++;
}
$MovieURL = $movie."/".$param['Category']."/".$param['Series']."/".$param['Episode'].".".$param['Extension'];
$MovieURL = rawurlencode( $MovieURL );
$param['MovieURL'] = $param['ServerURL'].$MovieURL;
$CategoryList = category_pickup( "./".$movie )[0];
$param['menu'] = menu_output($param, $CategoryList, $template, $TemplateFile['menu']);
$param['Breadcrumbs'] = breadcrumbs_output( $param, $param['Category'], $param['Series'], $param['Episode'], $template, $TemplateFile['breadcrumbs'] );
$param['SubNav'] = subnav_output( $param, $EpisodeList[0], $param['Category'], $param['Series'], $param['Episode'],$template, $TemplateFile['subnav'] );
$param['PageTitle'] = htmlspecialchars ( $param['Series']." | ".$param['Episode']." | ".$SiteTitle );
$TemplateFileLocation = $template."/".$TemplateFile['episode'];
echo template_engin($TemplateFileLocation, $param);
}
//カテゴリー直下動画視聴ページ
else if ( $param['Category'] != NULL && $param['Series'] == NULL && $param['Episode'] != NULL ){
$param['Category'] = htmlspecialchars_decode( $param['Category'] );
$param['Episode'] = htmlspecialchars_decode( $param['Episode'] );
$EpisodeListTemp = series_pickup( "./".$movie, $param['Category'] );
$j = 0;
for( $i = 0; $i < count( $EpisodeListTemp[0] );$i++ ){
$dir = "./".$movie."/".$param['Category']."/".$EpisodeListTemp[0][$i];
if( is_file( $dir ) ){
$EpisodeList[0][$j] = $EpisodeListTemp[0][$i];
$EpisodeList[1][$j] = $EpisodeListTemp[1][$i];
$j++;
}
}
$i = 0;
foreach ( $EpisodeList[0] as $value ){
$value = preg_replace( '/\.[^.]*$/', '', $value );
if ( $value == $param['Episode'] ){
$param['Extension'] = pathinfo( $EpisodeList[0][$i] )['extension'];
$param['ThumbnailURL'] = $EpisodeList[1][$i];
break;
}
$i++;
}
$MovieURL = "./".$movie."/".$param['Category']."/".$param['Episode'].".".$param['Extension'];
$MovieURL = rawurlencode( $MovieURL );
$param['MovieURL'] = $param['ServerURL'].$MovieURL;
$CategoryList = category_pickup( "./".$movie )[0];
$param['menu'] = menu_output($param, $CategoryList, $template, $TemplateFile['menu']);
$param['Breadcrumbs'] = breadcrumbs_output( $param, $param['Category'], $param['Series'], $param['Episode'], $template, $TemplateFile['breadcrumbs'] );
$param['Series'] = $param['Category'];
$EpisodeList[0] = preg_replace( '/\.[^.]*$/', '', $EpisodeList[0] );
$param['SubNav'] = subnav_output( $param, $EpisodeList[0], $param['Category'], $param['Series'], $param['Episode'],$template, $TemplateFile['subnav'] );
$param['SubNav'] = mb_str_replace( "&series=".rawurlencode( $param['Category'] ), "", $param['SubNav'] );
$param['PageTitle'] = htmlspecialchars ( $param['Category']." | ".$param['Episode']." | ".$SiteTitle );
$TemplateFileLocation = $template."/".$TemplateFile['episode'];
echo template_engin($TemplateFileLocation, $param);
}
//リダイレクト
else {
header("Location: ./");
exit;
}
//テンプレートエンジン
function template_engin($URL,$dataArray){
$html = file_get_contents($URL);
foreach ($dataArray as $key => $value){
$value = str_replace( '{', '{', $value);
$value = str_replace( '}', '}', $value);
$html = str_replace( '{{'.$key.'}}', $value, $html);
}
$html=preg_replace('/{{.*}}/','',$html);
return $html;
}
//カテゴリ一覧を取得
function category_pickup($dir){
global $DefaultThumb;
$ls = "./".$dir;
exec ( "ls \"".$ls."\"", $CategoryListTemp );
sort ( $CategoryListTemp, SORT_NATURAL );
foreach( $CategoryListTemp as $value ){
if( strpos( $value, '.jpg' ) === false ){
$CategoryList[] = $value;
$ThumbnailURL = $dir."/".$value."/".$value.".jpg";
if( file_exists( $ThumbnailURL ) ) {
$ThumbnailList[] = rawurlencode( $ThumbnailURL );
} else if( empty( $DefaultThumb ) && is_file( $ls."/".$value ) ) {
$ThumbnailList[] = thumbnail_generate( pathinfo( $value )['filename'] );
$CategoryList[$i] = pathinfo( $value )['filename'];
} else if ( empty( $DefaultThumb ) && is_dir( $ls."/".$value ) ){
$ThumbnailList[] = thumbnail_generate( $value );
} else {
$ThumbnailList[] = $DefaultThumb;
}
}
}
return [$CategoryList, $ThumbnailList];
}
//シリーズ一覧を取得
function series_pickup($dir,$Category){
global $DefaultThumb;
$Category = htmlspecialchars_decode( $Category );
$ls = "./".$dir."/".$Category;
exec ( "ls \"".$ls."\"", $SeriesListTemp );
sort ( $SeriesListTemp, SORT_NATURAL );
foreach( $SeriesListTemp as $value ){
if( strpos( $value, '.jpg' ) === false ){
$SeriesList[] = $value;
if( is_dir( $ls."/".$value ) ){
$ThumbnailURL = $dir."/".$Category."/".$value."/".$value.".jpg";
}
else if( is_file( $ls."/".$value ) ){
$ThumbnailURL = $dir."/".$Category."/".pathinfo( $value )['filename'].".jpg";
}
if( file_exists( $ThumbnailURL ) ) {
$ThumbnailList[] = rawurlencode( $ThumbnailURL );
} else if( empty( $DefaultThumb ) && is_file( $ls."/".$value ) ) {
$ThumbnailList[] = thumbnail_generate( pathinfo( $value )['filename'] );
} else if ( empty( $DefaultThumb ) && is_dir( $ls."/".$value ) ){
$ThumbnailList[] = thumbnail_generate( $value );
} else {
$ThumbnailList[] = $DefaultThumb;
}
}
}
return [$SeriesList, $ThumbnailList];
}
//エピソード一覧を取得
function episode_pickup($dir,$Category,$Series){
global $DefaultThumb;
$Category = htmlspecialchars_decode( $Category );
$Series = htmlspecialchars_decode( $Series );
$ls = "./".$dir."/".$Category."/".$Series;
exec ( "ls \"".$ls."\"", $EpisodeListTemp );
sort ( $EpisodeListTemp, SORT_NATURAL );
foreach( $EpisodeListTemp as $value ){
if( strpos( $value, '.jpg' ) === false ){
$EpisodeList[] = $value;
$ThumbnailURL = $dir."/".$Category."/".$Series."/".pathinfo( $value )['filename'].".jpg";
if( file_exists( $ThumbnailURL ) ) {
$ThumbnailList[] = rawurlencode( $ThumbnailURL );
} else if( empty( $DefaultThumb ) ) {
$ThumbnailList[] = thumbnail_generate( pathinfo( $value )['filename'] );
} else {
$ThumbnailList[] = $DefaultThumb;
}
}
}
foreach( $EpisodeList as $value ){
$Extension[] = pathinfo( $value )['extension'];
}
$EpisodeList = str_replace( $Extension, "", $EpisodeList );
return [$EpisodeList, $Extension, $ThumbnailList];
}
//メニューを出力
function menu_output($param, $CategoryList, $template, $TemplateFile){
foreach ($CategoryList as $value){
$value = htmlspecialchars( $value );
$param['CategoryList'] = $value;
$value = rawurlencode( $value );
$param['CategoryURL'] = "?category=".$value;
$TemplateFileLocation = $template."/".$TemplateFile;
$menu .= template_engin($TemplateFileLocation, $param);
}
return $menu;
}
//パンくずリスト出力
function breadcrumbs_output( $param, $Category, $Series, $Episode, $template, $TemplateFile ){
$TemplateFileLocation = $template."/".$TemplateFile;
if ( $Category != null ){
$param['Breadcrumbs'] = htmlspecialchars( $Category );
$param['BreadcrumbsURL'] = "?category=".rawurlencode( $param['Breadcrumbs'] );
$breadcrumbs .= template_engin($TemplateFileLocation, $param);
}
if ( $Series != null ){
$param['Breadcrumbs'] = htmlspecialchars( $Series );
$param['BreadcrumbsURL'] .= "&series=".rawurlencode( $param['Breadcrumbs'] );
$breadcrumbs .= template_engin($TemplateFileLocation, $param);
}
if ( $Episode != null ){
$param['Breadcrumbs'] = htmlspecialchars( $Episode );
$param['BreadcrumbsURL'] .= "&episode=".rawurlencode( $param['Breadcrumbs'] );
$breadcrumbs .= template_engin($TemplateFileLocation, $param);
}
return $breadcrumbs;
}
//サブナビゲーション出力
function subnav_output($param, $EpisodeList, $Category, $Series, $Episode, $template, $TemplateFile ){
$TemplateFileLocation = $template."/".$TemplateFile;
$i = 0;
$count = count( $EpisodeList ) - 1;
foreach( $EpisodeList as $value ){
if ( $value == $Episode && $i == 0 && $count > 0 ){
$Category = htmlspecialchars( $Category );
$Series = htmlspecialchars( $Series );
$Episode = htmlspecialchars( $Episode );
$param['SubNav'] = $EpisodeList[$i];
$param['SubNavURL'] = "#";
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $Series;
$param['SubNavURL'] = "?category=".rawurlencode( $Category )."&series=". rawurlencode( $Series );
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $EpisodeList[$i + 1];
$param['SubNavURL'] = $param['SubNavURL']."&episode=".rawurlencode( $EpisodeList[$i + 1] );
$SubNavList .= template_engin($TemplateFileLocation, $param);
break;
} else if ( $value == $Episode && $i == $count && $count > 0 ) {
$Category = htmlspecialchars( $Category );
$Series = htmlspecialchars( $Series );
$Episode = htmlspecialchars( $Episode );
$param['SubNav'] = $EpisodeList[$i - 1];
$param['SubNavURL'] = "?category=".rawurlencode( $Category )."&series=".rawurlencode( $Series )."&episode=".rawurlencode( $EpisodeList[$i - 1] );
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $Series;
$param['SubNavURL'] = "?category=".rawurlencode( $Category )."&series=".rawurlencode( $Series );
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $EpisodeList[$i];
$param['SubNavURL'] = "#";
$SubNavList .= template_engin($TemplateFileLocation, $param);
break;
} else if ( $value == $Episode && $i < $count && $count > 0 ) {
$Category = htmlspecialchars( $Category );
$Series = htmlspecialchars( $Series );
$Episode = htmlspecialchars( $Episode );
$param['SubNav'] = $EpisodeList[$i - 1];
$param['SubNavURL'] = "?category=".rawurlencode( $Category )."&series=".rawurlencode( $Series )."&episode=".rawurlencode( $EpisodeList[$i - 1] );
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $Series;
$param['SubNavURL'] = "?category=".rawurlencode( $Category )."&series=".rawurlencode( $Series );
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $EpisodeList[$i + 1];
$param['SubNavURL'] = $param['SubNavURL']."&episode=".rawurlencode( $EpisodeList[$i + 1] );
$SubNavList .= template_engin($TemplateFileLocation, $param);
break;
} else if ( $value == $Episode && $count == 0 ) {
$Category = htmlspecialchars( $Category );
$Series = htmlspecialchars( $Series );
$param['SubNav'] = $EpisodeList[$i];
$param['SubNavURL'] = "#";
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $Series;
$param['SubNavURL'] = "?category=".rawurlencode( $Category )."&series=".rawurlencode( $Series );
$SubNavList .= template_engin($TemplateFileLocation, $param);
$param['SubNav'] = $EpisodeList[$i];
$param['SubNavURL'] = "#";
$SubNavList .= template_engin($TemplateFileLocation, $param);
}
$i++;
}
return $SubNavList;
}
//コンテンツ一覧を出力
function contents_output($param, $ContentsList, $ThumbnailURL, $template, $TemplateFile){
global $movie;
$dir = "./".$movie."/".$param['Category'];
$i = 0;
foreach ($ContentsList as $value){
$param['ContentsList'] = htmlspecialchars_decode( $value ).$param['Extension'];
$param['ContentsURL'] = "?category=".rawurlencode( $value );
$param['ThumbnailURL'] = $ThumbnailURL[$i];
if ( $param['Category'] != NULL && is_null($param['Series']) && is_null($param['Episode']) && is_dir( $dir."/".$value ) ) {
$param['ContentsURL'] = "?category=".rawurlencode( $param['Category'] )."&series=".rawurlencode( $value );
}
else if ( $param['Category'] != NULL && is_null($param['Series']) && is_null($param['Episode']) && is_file( $dir."/".$value ) ) {
$value = pathinfo( $value )['filename'];
$param['ContentsList'] = $value;
$param['ContentsURL'] = "?category=".rawurlencode( $param['Category'] )."&episode=".rawurlencode( $value );
}
else if ( $param['Series'] != NULL && $param['Series'] != NULL && is_null($param['Episode']) ) {
$param['ContentsURL'] = "?category=".rawurlencode( $param['Category'] )."&series=".rawurlencode( $param['Series'] )."&episode=".rawurlencode( $value );
}
else if ( $param['Series'] != NULL && $param['Series'] != NULL && is_null($param['Episode']) ) {
$param['ContentsURL'] = "?category=".rawurlencode( $param['Category'] )."&episode=".rawurlencode( $value );
}
$param['ContentsURL'] = htmlspecialchars( $param['ContentsURL'] );
$TemplateFileLocation = $template."/".$TemplateFile;
$contents .= template_engin($TemplateFileLocation, $param);
$i++;
}
return $contents;
}
//サムネイル生成
function thumbnail_generate($str){
global $font;
$width = 640;
$height = 360;
$font_size = 50;
$im = imagecreate ($width, $height);
$bg = ImageColorAllocate ($im, 255, 255, 255);
$tb = imagettfbbox($font_size, 0, $font, $str);
$target_width = $width - 20;
$text_width = $tb[2] - $tb[6];
if ( $target_width < $text_width ){
$scale = $target_width / $text_width;
$font_size = $font_size * $scale;
$tb = imagettfbbox($font_size, 0, $font, $str);
}
$x = ceil(($width - $tb[2]) / 2);
$y = ceil(($height - $tb[5]) / 2);
$font_color = ImageColorAllocate ($im, 100, 100, 100);
ImageTTFText ($im, $font_size, 0, $x, $y, $font_color, $font, $str);
ob_start();
ImagePng( $im );
$content = "data:image/png;base64,".base64_encode( ob_get_contents());
ob_end_clean();
ImageDestroy ($im);
return $content;
}
//マルチバイト対応str_replace
function mb_str_replace($search, $replace, $haystack, $encoding="UTF-8"){
// 検索先は配列か?
$notArray = !is_array($haystack) ? TRUE : FALSE;
// コンバート
$haystack = $notArray ? array($haystack) : $haystack;
// 検索文字列の文字数取得
$search_len = mb_strlen($search, $encoding);
// 置換文字列の文字数取得
$replace_len = mb_strlen($replace, $encoding);
foreach ($haystack as $i => $hay){
// マッチング
$offset = mb_strpos($hay, $search);
// 一致した場合
while ($offset !== FALSE){
// 差替え処理
$hay = mb_substr($hay, 0, $offset).$replace.mb_substr($hay, $offset + $search_len);
$offset = mb_strpos($hay, $search, $offset + $replace_len);
}
$haystack[$i] = $hay;
}
return $notArray ? $haystack[0] : $haystack;
}
?>