require_once('../prepare.php');
require_once('lib/diary_function.php');
$free_flg = false;
//- 表示対象日記リスト情報取得
if(!empty($p['id'])){
$diary_detail = get_DiaryDetail_id($p['id']);
if(
date("Ymd",mktime(
0,
0,
0,
substr($diary_detail[0]['open_date'],5,2),
substr($diary_detail[0]['open_date'],8,2),
substr($diary_detail[0]['open_date'],0,4)
))
==
date("Ymd",mktime(
0,
0,
0,
date("m"),
date("d"),
date("Y"))
)
)
{
$free_flg = true;
}
}else{
$diary_detail = get_DiaryDetail();
$free_flg = true;
}
//- メンバーチェック
if(!$free_flg){
if("e" == $p['carrier']){
chdir(dirname(__FILE__) . "/authcheck");
require_once("../authcheck/authcheck.php");
chdir(dirname(__FILE__));
}
$db = u4user_open();
if(!get_UserDetail_uid($db, $p['uid'], '0', '1') && MEMBER_CHECK){
header("Location: ".MEMBER_REGIST_URL."?contents=".substr(strrchr(dirname( __FILE__ ) , '/'), 1));
exit;
}
u4user_close($db);
}
function diary_detail( $p , $diary_detail)
{
//- 有料会員かどうか?(無料公開時に有料登録誘導リンク有無判定のため)
$db = u4user_open();
if(!get_UserDetail_uid($db, $p['uid'], '0', '1') && MEMBER_CHECK){
$free_user = 1;
}
u4user_close($db);
$this->db = cs4_open();
//- コメント取得
$comment_list = get_UserComment($diary_detail[0]['uniq_id']);
$comment_count = count($comment_list);
//- コメント表示最大件数
$max_line = 3;
//- レシピ写真サイズ判定
if("1" == $p['version']){
$photo_size = 1;
}else{
$photo_size = 0;
}
//- au Ver.2 対応
if("e" == $p['carrier'] && $p['version'] == "2"){
$photo_size = 1;
}
//- ディレクトリ名(コンテンツ名)取得
$dir_name = substr(strrchr(dirname( __FILE__ ) , '/'), 1);
// テンプレート読み込み
$template =& loadTemplate( $p );
$template->setVariable('recipe_name',$diary_detail[0]['rcp_nm']);
$img_filename = array(sprintf("%s_n.jpg",$diary_detail[0]['uniq_id']),sprintf("%s_n-s.jpg",$diary_detail[0]['uniq_id']));
switch($photo_size){
case "0":
$img_path = sprintf("%s/%s",constant('IMG_DIR_RECIPE'),$img_filename[0]);
$another_url = sprintf("%s/%s",constant('IMG_DIR_RECIPE'),$img_filename[1]);
if(file_exists($img_path)){
$template->setVariable('recipe_image',sprintf("",str_replace(KTY_SERVER_ROOT,"",$img_path)));
}
clearstatcache();
break;
case "1":
$img_path = sprintf("%s/%s",constant('IMG_DIR_RECIPE'),$img_filename[1]);
$another_url = sprintf("%s/%s",constant('IMG_DIR_RECIPE'),$img_filename[0]);
if(file_exists($img_path)){
$template->setVariable('recipe_image',sprintf("",str_replace(KTY_SERVER_ROOT,"",$img_path)));
}
clearstatcache();
break;
default:
break;
}
//- 画像セット
switch($photo_size){
case "0":
if(!empty($diary_detail[0]['test_kty_image'])){
$template->setCurrentBlock('__ShowImage__');
$template->setVariable('image_id',$diary_detail[0]['test_kty_image']);
$template->parseCurrentBlock();
}else{
$template->hideBlock('__ShowImage__');
}
break;
case "1":
if(!empty($diary_detail[0]['test_kty_image_mini'])){
$template->setCurrentBlock('__ShowImage__');
$template->setVariable('image_id',$diary_detail[0]['test_kty_image_mini']);
$template->parseCurrentBlock();
}else{
$template->hideBlock('__ShowImage__');
}
break;
}
//- 公開日セット
$tmp = explode(" ",$diary_detail[0]['open_date']);
$date_arr = explode("-",$tmp[0]);
$day = get_Day(date("w",mktime(0,0,0,$date_arr[1],$date_arr[2],$date_arr[0])));
$date_str = sprintf("%d年%d月%d日",$date_arr[0],$date_arr[1],$date_arr[2]);
$template->setVariable('open_date',$date_str);
//- タイトルセット
$template->setVariable('title',$diary_detail[0]['title']);
//- コメント件数セット
$template->setVariable('comment_count',sprintf("%d",$comment_count));
//- ライターセット
/*
$writer = get_DiaryWriter($diary_detail[0]['test_writer']);
$template->setVariable('writer',$writer);
*/
//- 本文セット
$template->setVariable('body',$diary_detail[0]['test_kty_body']);
//- 有料登録案内
if($free_user){
$template->setCurrentBlock('__Free__');
if("e" == $p['carrier']){
$template->setVariable('toll_member','メンバー');
}else{
$template->setVariable('toll_member','マイメニュー');
}
$template->parseCurrentBlock();
$template->hideBlock('__Toll__');
}else{
$template->setCurrentBlock('__Toll__');
$template->setVariable('mail_subject',$tmp[0].$diary_detail[0]['title']);
$template->parseCurrentBlock();
$template->hideBlock('__Free__');
}
//- 前日リンク
/*
if(!empty($diary_detail[1])){
$writer = "";
$writer = get_DiaryWriter($diary_detail[1]['test_writer']);
$template->setCurrentBlock('__Yesterday__');
$template->setVariable('diary_id',$diary_detail[1]['uniq_id']);
$template->setVariable('writer',$writer);
$template->parseCurrentBlock();
}
//- 前々日リンク
if(!empty($diary_detail[2])){
$writer = "";
$writer = get_DiaryWriter($diary_detail[2]['test_writer']);
$template->setCurrentBlock('__2Days_before__');
$template->setVariable('diary_id',$diary_detail[2]['uniq_id']);
$template->setVariable('writer',$writer);
$template->parseCurrentBlock();
}
*/
//var_dump($comment_list);
//- 投稿コメントリスト表示
if(0 < $comment_count){
$show_count = 0;
$no_images = "";
for($i=0;$i < $comment_count && $show_count < $max_line;$i++){
//- 写真のないものはスルー
if(empty($comment_list[$i]['image'])){
$no_images[] = $comment_list[$i];
continue;
}
$filepath = sprintf("%s/%s_n-thm.jpg",IMG_DIR_COMMENT,$comment_list[$i]['uniq_id']);
if(!empty($comment_list[$i]['image']) && file_exists($filepath)){
$template->setCurrentBlock('__ImgLink__');
$template->setVariable('file_path',str_replace(KTY_SERVER_ROOT,"",$filepath));
$template->parseCurrentBlock();
}else{
$template->hideBlock('__ImgLink__');
}
if(($i + 1) < $comment_count && ($i + 1) < $max_line ){
$template->TouchBlock('__Line__');
}elseif(($show_count + 1) < $max_line && !empty($no_images)){
$template->TouchBlock('__Line__');
}
$template->setCurrentBlock('__List__');
$template->setVariable('user_name',$comment_list[$i]['contributor']);
$tmp = explode(" ",$comment_list[$i]['post_date']);
$post_date = explode("-",$tmp[0]);
$template->setVariable('post_date',sprintf("%s月%s日",$post_date[1],$post_date[2]));
$template->setVariable('uniq_id',$comment_list[$i]['uniq_id']);
$template->setVariable('comment_body',mb_substr($comment_list[$i]['body'],0,10));
$template->parseCurrentBlock();
$show_count++;
}
//- スペースに余裕があれば写真なしも表示
$rest_line = $max_line - $show_count;
if((0 < $rest_line) && !empty($no_images)){
for($i=0;$i<$rest_line && !empty($no_images[$i]) ;$i++){
if(($i + 1) < $rest_line && ($i + 1) < $max_line ){
$template->TouchBlock('__Line__');
}
$template->setCurrentBlock('__List__');
$template->setVariable('user_name',$no_images[$i]['contributor']);
$tmp = explode(" ",$no_images[$i]['post_date']);
$post_date = explode("-",$tmp[0]);
$template->setVariable('post_date',sprintf("%s月%s日",$post_date[1],$post_date[2]));
$template->setVariable('uniq_id',$no_images[$i]['uniq_id']);
$template->setVariable('comment_body',mb_substr($no_images[$i]['body'],0,10));
$template->parseCurrentBlock();
}
}
if($comment_count > $max_line){
$template->setCurrentBlock('__ListLink__');
$template->setVariable('diary_id',$diary_detail[0]['uniq_id']);
$template->parseCurrentBlock();
}
$template->TouchBlock('__Comment__');
}else{
$template->hideBlock('__Comment__');
}
//- コンテンツトップ戻りリンク
if(strstr(date("Y-m-d"),$diary_detail[0]['open_date'])){
$template->hideBlock('__ReturnContentsTop__');
}else{
$template->setCurrentBlock('__ReturnContentsTop__');
$template->setVariable('contents_top_url','diary_detail.php');
$template->setVariable('contents_top',DIARY_NAME);
$template->parseCurrentBlock();
}
//- access_log 記録
// $ret = bsc_insert_acslog($this->db,$detail[0],"r",$p['uid']);
$template->show();
cs4_close($this->db);
}
diary_detail( $p , $diary_detail);
?>