<?php
/**
* CSRF対策クラス
*
* クロスサイトリクエストフォージェリ脆弱性の対策を行うクラス
*/
class csrf {
/**
* 第三者が知り得ない秘密情報(トークン)の値を取得する
*
*/
static public function get_token() {
return session_id();
}
/**
* トークンの値をチェックする
*
*/
static public function check_token() {
// トークン確認
if(true === isset($_POST['token'])) {
// hiddenからPOSTされたトークンとセッションIDが違う場合は不正な遷移
if(0 !== strcmp($_POST['token'], self::get_token())) {
throw new custom_exception('トークン値相違', 1);
}
} else {
// hiddenからPOSTされたトークンが未設定時も不正な遷移
throw new custom_exception('トークン値未設定', 1);
}
}
}
?>
<?php
/**
* 単一値専用のテンプレート置換処理クラス
*
* HTMLテンプレート内の単一値の部分の置換を行うクラス
*
* @access public
* @create 2011/01/30
* @version 1.0
*/
class template_convert_single
{
/**
* テンプレート置換ロジック実行
*
* @access public
* @param view $view ビュークラスインスタンス
*/
public function convert_template($view)
{
$output_html = $view->get_output_html();
// 区切り開始文字列の直前までの文字列
$output_buf = mb_strstr($output_html, ';;;', true);
// 区切り開始文字列以降の文字列
$after = mb_strstr($output_html, ';;;');
// 区切り終了文字列の直後からの文字列
$name_last_after = mb_substr(mb_strstr(mb_substr($after, 3), ';;;'), 3);
// テンプレート側で設定してある名前
$name = explode(';;;', $after);
// 置換対象のデータ
$data = $view->get_action()->get_template_convert()->get_single_array_val($name[1]);
if (true === isset($data))
{
// データ有り
$output_buf .= $data . $name_last_after;
}
else
{
// データ無し
$output_buf .= $name_last_after;
}
$view->set_output_html($output_buf);
}
}
<?php
/**
* 複数値専用のテンプレート置換処理クラス
*
* HTMLテンプレート内の複数値の部分の置換を行うクラス
*
* @access public
* @create 2011/01/30
* @version 1.0
*/
class template_convert_multi
{
/**
* テンプレート置換ロジック実行
*
* @access public
* @param view $view ビュークラスインスタンス
*/
public function convert_template($view)
{
$output_html = $view->get_output_html();
// 区切り開始文字列の直前までの文字列
$output_buf = mb_strstr($output_html, ':::', true);
// 区切り開始文字列以降の文字列
$after = mb_strstr($output_html, ':::');
// 区切り開始文字列以降の文字列を、区切り開始文字列で分割した配列
$after_array = explode(':::', $after);
// テンプレート側で設定してある名前
$name = explode('@', $after_array[1]);
// 置換対象のデータ
$data = $view->get_action()->get_template_convert()->get_multi_array_val($name[0]);
if (true === isset($data))
{
// データ有り
$multi_flag = false;
// チェックボックスの場合のみ、$dataは配列になっている
if (true === is_array($data))
{
$data_length = count($data);
for ($i = 0; $i < $data_length; $i++)
{
// チェックボックスでどの値を選択するかを判定
if (0 === strcmp($data[$i], $name[1]))
{
$multi_flag = true;
break;
}
}
}
else
{
// セレクトボックス・ラジオボックスでどの値を選択するかを判定
if (0 === strcmp($data, $name[1]))
{
$multi_flag = true;
}
}
// 判定をして選択か未選択状態の文字列を足しこむ
if (true === $multi_flag)
{
$output_buf .= $view->get_action()->get_template_convert()->get_multi_array_yes_val($name[0]);
}
else
{
$output_buf = rtrim($output_buf);
$output_buf .= $view->get_action()->get_template_convert()->get_multi_array_no_val($name[0]);
}
}
// 区切り終了文字列の直後からの文字列をくっつけていく
$output_buf .= mb_substr(mb_strstr(mb_substr($after, 3), ':::'), 3);
$view->set_output_html($output_buf);
}
}
<?php
/**
* ループ専用のテンプレート置換処理クラス
*
* HTMLテンプレート内のループの部分の置換を行うクラス
*/
class template_convert_loop extends template_convert {
/**
* テンプレート置換ロジック実行
*
*/
public function convert_template($view) {
$output_html = $view->get_output_html();
$output_buf = mb_strstr($output_html, '|||', true);
$after = mb_strstr($output_html, '|||');
$after_array = explode('|||', $after);
$name = $after_array[1];
$body = $after_array[2];
$rows = $view->get_loop_array_value($name);
if (true === isset($rows)) {
// ループ名が設定されている時のみデータもある
$row_size = count($rows);
// 表示する行数分繰り返す
for ($i = 0; $i < $row_size; $i++) {
// 初期化
$body_buf = $body;
// strstrは検索文字列が見つからない時はfalseを返すので、その間繰り返し
while (false !== ($data_before = mb_strstr($body_buf, ';;;', true))) {
$data_after = mb_substr(mb_strstr(mb_substr(mb_strstr($body_buf, ';;;'), 3), ';;;'), 3);
$data_array = explode(';;;', $body_buf);
// モデルのゲッターを実行しデータを取得
$data_value = utility::create_accessor_name($rows[$i], 'get', $data_array[1]);
$body_buf = $data_before . $data_value . $data_after;
}
$output_buf .= $body_buf;
}
}
$output_buf .= $after_array[4];
$view->set_output_html($output_buf);
}
}
?>
Author:kitoku
「奇特」を目指しているITエンジニアです。ホームページ:http://www.kitoku-magic.net/