-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVideoFilesController.php
More file actions
110 lines (100 loc) · 3.07 KB
/
VideoFilesController.php
File metadata and controls
110 lines (100 loc) · 3.07 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
<?php
/**
* サムネイル、動画の表示 Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('Controller', 'Controller');
App::uses('Current', 'NetCommons.Utility');
App::uses('NetCommonsSecurity', 'NetCommons.Utility');
/**
* サムネイル、動画の表示 Controller
* パフォーマンス改善のため、NetCommonsAppController(VideosAppController)を継承しない
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\Videos\Controller
* @property Video $Video
* @property DownloadComponent $Download
*/
class VideoFilesController extends Controller {
/**
* use model
*
* @var array
*/
public $uses = array(
'Videos.Video'
);
/**
* use components
*
* @var array
*/
public $components = array(
'Files.Download',
//Currentで必要なため、定義する
'Session',
'Auth',
);
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
// NetCommonsAppController(VideosAppController) を継承しないため、ここでカレントデータセット
$instance = Current::getInstance();
$instance->initialize($this);
// $componentsにAuthが設定されると、パブリックで公開された動画がログインしないと見れなくなるため、functionのfileを除外する
// @see https://github.com/NetCommons3/NetCommons3/issues/1540
$this->Auth->allow('file');
}
/**
* サムネイル、動画の表示
*
* @return CakeResponse
* @throws NotFoundException 表示できない記事へのアクセス
*/
public function file() {
if (! (new NetCommonsSecurity())->enableBadIps()) {
throw new NotFoundException();
}
// ここから元コンテンツを取得する処理
$key = $this->params['key'];
$conditions = $this->Video->getConditions();
$conditions['Video.key'] = $key;
$query = array(
'conditions' => $conditions,
);
$video = $this->Video->find('first', $query);
// ここまで元コンテンツを取得する処理
// ダウンロード実行
if ($video) {
//NC2からNC3で移行するとサムネイルが移行されないため、サムネイル画像がないときはNoImageを表示させる
//@see https://github.com/NetCommons3/NetCommons3/issues/1617
try {
$response = $this->Download->doDownload($video['Video']['id']);
} catch (Exception $ex) {
if (!empty($this->request->params['pass']) &&
$this->request->params['pass'][0] === Video::THUMBNAIL_FIELD) {
//NoImageを表示する
$noimagePath = CakePlugin::path('Videos') .
'webroot' . DS . 'img' . DS . 'thumbnail_noimage.png';
$this->response->file($noimagePath, ['name' => 'No Image']);
$response = $this->response;
} else {
throw $ex;
}
}
return $response;
} else {
// 表示できないなら404
throw new NotFoundException();
}
}
}