1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* View |
4
|
|
|
* |
5
|
|
|
* 静的ページ表示機能を実現するためのクラス |
6
|
|
|
* |
7
|
|
|
* @package risoluto |
8
|
|
|
* @author Risoluto Developers |
9
|
|
|
* @license http://opensource.org/licenses/bsd-license.php new BSD license |
10
|
|
|
* @copyright (C) 2008-2015 Risoluto Developers / All Rights Reserved. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
//------------------------------------------------------// |
14
|
|
|
// 名前空間の定義 |
15
|
|
|
//------------------------------------------------------// |
16
|
|
|
namespace RisolutoApps\Pages; |
17
|
|
|
|
18
|
|
|
//------------------------------------------------------// |
19
|
|
|
// クラス定義 |
20
|
|
|
//------------------------------------------------------// |
21
|
|
|
class View extends \Risoluto\RisolutoControllerBase implements \Risoluto\RisolutoControllerInterface |
22
|
|
|
{ |
23
|
|
|
// View関連の処理を使用する |
24
|
|
|
use \Risoluto\RisolutoViewTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* play() |
28
|
|
|
* |
29
|
|
|
* 主処理を行う |
30
|
|
|
* |
31
|
|
|
* @access public |
32
|
|
|
* |
33
|
|
|
* @param void |
34
|
|
|
* |
35
|
|
|
* @return void なし |
36
|
|
|
*/ |
37
|
|
|
public function play() |
38
|
|
|
{ |
39
|
|
|
// パラメタを取得し、空だった時はデフォルトの画面を取得する |
40
|
|
|
$params = $this->getParam(); |
41
|
|
|
if (empty( $params ) or !preg_match( '/^[[:alnum:]_-].*$/', $params[ 0 ] )) { |
42
|
|
|
$tmpl = 'Top'; |
43
|
|
|
} else { |
44
|
|
|
// パラメタ中のディレクトリセパレタを編集してセット |
45
|
|
|
$tmpl = str_replace( '_', DS, $params[ 0 ] ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// デフォルトヘッダ情報の取得 |
49
|
|
|
$header = $this->getDefaultHeader(); |
50
|
|
|
|
51
|
|
|
// ファイルの実在を確認し、優先順に沿って処理を実施 |
52
|
|
|
$basepath = RISOLUTO_APPS . 'RisolutoApps/Pages/shelf/' . str_replace( '../', '', $tmpl ); |
53
|
|
|
clearstatcache( true ); |
54
|
|
|
if (file_exists( $basepath . '.tpl' )) { |
55
|
|
|
//--- .tplファイルが存在するときはテンプレートエンジンで処理した結果を出力する |
56
|
|
|
$tmpl .= '.tpl'; |
57
|
|
|
|
58
|
|
|
// テンプレートエンジン関連の処理 |
59
|
|
|
$assign_value = [ 'header' => $header, 'pagename' => $params[ 0 ], 'options' => $params ]; |
60
|
|
|
echo trim( $this->risolutoView( $assign_value, 'fetch', 'Pages/shelf/', $tmpl ) ); |
61
|
|
|
} elseif (file_exists( $basepath . '.md' )) { |
62
|
|
|
//--- .mdファイルが存在するときはパースしてから処理する |
63
|
|
|
// タイトルだけ置き換えてヘッダとフッタを取得 |
64
|
|
|
$header[ 'title' ] = ( isset( $params[ 0 ] ) and !empty( $params[ 0 ] ) ) ? $params[ 0 ] : 'Top'; |
65
|
|
|
$assign_value = [ 'header' => $header, 'pagename' => $params[ 0 ], 'options' => $params ]; |
66
|
|
|
$parts_header = $this->risolutoView( $assign_value, 'fetch', 'Pages/', 'dummy_header.tpl' ); |
67
|
|
|
$parts_footer = $this->risolutoView( $assign_value, 'fetch', 'Pages/', 'dummy_footer.tpl' ); |
68
|
|
|
|
69
|
|
|
// 本体をパースして取得 |
70
|
|
|
/** @noinspection PhpUndefinedNamespaceInspection */ |
71
|
|
|
$parts_body = \Michelf\MarkdownExtra::defaultTransform( file_get_contents( $basepath . '.md' ) ); |
72
|
|
|
|
73
|
|
|
// 画面に出力 |
74
|
|
|
echo trim( $parts_header . $parts_body . $parts_footer ); |
75
|
|
|
} elseif (file_exists( $basepath . '.raw' )) { |
76
|
|
|
//--- .rawファイルが存在するときは取得した内容をそのまま出力 |
77
|
|
|
echo trim( file_get_contents( $basepath . '.raw' ) ); |
78
|
|
|
} else { |
79
|
|
|
//--- いずれも存在しないときはエラー |
80
|
|
|
$conf = new \Risoluto\Conf; |
81
|
|
|
$conf->parse( RISOLUTO_CONF . 'risoluto.ini' ); |
82
|
|
|
|
83
|
|
|
$error = $conf->getIni( 'SEQ', 'error' ); |
84
|
|
|
\Risoluto\Url::redirectTo( $error ); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |