ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Ignore:
Timestamp:
Apr 4, 2008, 6:05:02 PM (15 years ago)
Author:
cybaron
Message:

・db/album.php不要関数削除
・アルバム機能 ロジック整理。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE/branches/work/asano/pne_album/webapp/lib/db/album.php

    r6284 r6309  
    55 */
    66
    7 /**
    8  * 指定メンバーの日記カテゴリリストを取得する
    9  *
    10  * @param int $c_member_id
    11  * @return array
    12  */
    13 /*
    14 function db_album_category_list4c_member_id($c_member_id)
    15 {
    16     $sql = 'SELECT c_album_category_id, category_name FROM c_album_category ' .
    17         'WHERE c_member_id = ?';
    18     $result = db_get_all($sql, array(intval($c_member_id)));
    19 
    20     return $result;
    21 }
    22 */
    23 /*
    24 function fetch_inc_entry_point_h_album_add(&$smarty)
    25 {
    26     $target = 'h_album_add';
    27 
    28     $contents = array();
    29     for ($i = 1; $i <= 3; $i++) {
    30         $tpl = sprintf('db:inc_entry_point_%s_%d', $target, $i);
    31         $contents[$i] = fetch_from_db($tpl, $smarty);
    32     }
    33     return $contents;
    34 }
    35 */
    36 /**
    37  * カテゴリ名からカテゴリIDを得る
    38  *
    39  * @param int $c_member_id
    40  * @param string $category_name
    41  * @return bool
    42  */
    43 /*
    44 function db_album_get_category_id4category_name($c_member_id, $category_name)
    45 {
    46     $sql = 'SELECT c_album_category_id FROM c_album_category ' .
    47         'WHERE category_name LIKE ? AND c_member_id = ?';
    48     return db_get_one($sql, array($category_name, intval($c_member_id)));
    49 }
    50 */
    51 /**
    52  * カテゴリIDからカテゴリ名を得る
    53  */
    54 /*
    55 function db_album_get_category_name4category_id($category_id)
    56 {
    57     $sql = 'SELECT category_name FROM c_album_category ' .
    58         'WHERE c_album_category_id = ?';
    59     return db_get_one($sql, array($category_id));
    60 }
    61 */
    62 /**
    63  * 日記IDからカテゴリリストを得る
    64  *
    65  * @param int $c_album_id
    66  * @return array
    67  */
    68 /*
    69 function db_album_category_list4c_album_id($c_album_id)
    70 {
    71     $sql = 'SELECT c_album_category_id FROM c_album_category_album WHERE c_album_id = ?';
    72     $category_list = db_get_col($sql, array(intval($c_album_id)));
    73     $ids = join(',', $category_list);
    74 
    75     $sql = 'SELECT c_album_category_id, category_name FROM c_album_category' .
    76         ' WHERE c_album_category_id IN ('.$ids.')';
    77     return db_get_all($sql);
    78 }
    79 */
    80 /**
    81  * カテゴリIDから日記を得る
    82  *
    83  * @param int $c_album_category_id
    84  * @return array
    85  */
    86 /*
    87 function db_album_list4c_album_category_id($c_member_id, $c_album_category_id, $u = null, $page_size, $page)
    88 {
    89     $sql = 'SELECT c_album_id FROM c_album_category_album WHERE c_album_category_id = ?';
    90     $album_list = db_get_col($sql, array(intval($c_album_category_id)));
    91     $ids = join(',', $album_list);
    92 
    93     $pf_cond = db_album_public_flag_condition($c_member_id, $u);
    94     $sql = 'SELECT * FROM c_album' .
    95         ' WHERE c_album_id IN ('.$ids.') AND c_member_id = ? ORDER BY r_datetime DESC';         //' . $pf_cond . '
    96     $list = db_get_all($sql, array($c_member_id));
    97    
    98     $total_num = count($list);
    99 
    100 
    101 
    102     $sql1 = 'SELECT nickname FROM c_member WHERE c_member_id = ?';
    103    
    104     foreach ($list as $key => $c_album) {
    105         $list[$key]['num_comment'] = db_album_count_c_album_comment4c_album_id($c_album['c_album_id']);
    106         $list[$key]['nickname'] = db_get_one($sql1,$c_album['c_member_id']);
    107         $list[$key]['category'] = db_album_category_list4c_album_id($c_album['c_album_id']);
    108     }
    109    
    110     if ($total_num != 0) {
    111         $total_page_num =  ceil($total_num / $page_size);
    112         if ($page >= $total_page_num) {
    113             $next = false;
    114         } else {
    115             $next = true;
    116         }
    117 
    118         if ($page <= 1) {
    119             $prev = false;
    120         } else {
    121             $prev = true;
    122         }
    123     }
    124 
    125     return array($list, $prev, $next,$total_num);
    126 }
    127 */
    128 function db_check_c_album_image_exist($c_album_id){
    129     $sql = 'SELECT c_album_id FROM c_album_image WHERE c_album_id = ?';
    130     $params = array(intval($c_album_id));
    131    
    132     return db_get_one($sql,$params);
    133 }
    134 
    135 /**
    136  * カテゴリを追加する
    137  *
    138  * @param int $c_member_id
    139  * @param int $category_name
    140  */
    141 /*
    142 function db_album_category_insert_category($c_member_id, $category_name)
    143 {
    144     $data = array(
    145         'c_member_id' => intval($c_member_id),
    146         'category_name' => $category_name,
    147         'r_datetime' => db_now(),
    148     );
    149     return db_insert('c_album_category', $data);
    150 }
    151 */
    152 /**
    153  * カテゴリを削除する
    154  *
    155  * @param int $c_album_category_id
    156  */
    157 /*
    158 function db_album_category_delete_category($c_album_category_id)
    159 {
    160     $sql = 'DELETE FROM c_album_category WHERE c_album_category_id = ?';
    161     db_query($sql, array($c_album_category_id));   
    162 }
    163 */
    164 /**
    165  * カテゴリと日記を関連づける
    166  *
    167  * @param int $c_album_id
    168  * @param int $c_album_category_id
    169  */
    170 /*
    171 function db_album_category_insert_c_album_category_album($c_album_id, $c_album_category_id)
    172 {
    173     $data = array(
    174         'c_album_id' => intval($c_album_id),
    175         'c_album_category_id' => intval($c_album_category_id),
    176     );
    177     db_insert('c_album_category_album', $data);
    178 }
    179 */
    180 
    181 /**
    182  * カテゴリと日記の関連づけを削除する
    183  */
    184 /*
    185 function db_album_category_delete_c_album_category_album($c_album_id)
    186 {
    187     $album_category_list = db_album_category_list4c_album_id($c_album_id);
    188 
    189     $sql = 'DELETE FROM c_album_category_album WHERE c_album_id = ?';
    190     db_query($sql, array($c_album_id));
    191 
    192     foreach($album_category_list as $value) {
    193         $sql = 'SELECT COUNT(*) FROM c_album_category_album'.
    194             ' WHERE c_album_category_id = ?';
    195         $c_album_category_id = $value['c_album_category_id'];
    196         $is_album = (bool)db_get_one($sql, array(intval($c_album_category_id)));
    197         if (!$is_album) {  //カテゴリに関連付いた日記が存在しない
    198             db_album_category_delete_category($c_album_category_id);
    199         }
    200     }
    201 }
    202 */
    2037/**
    2048 * db_album_public_flag_condition
     
    25054}
    25155
    252 /*
     56/**
    25357 * あるメンバーのアルバムのサブジェクト一覧を取得
    25458 * @param int $c_member_id target_member_id
     
    26872
    26973/**
    270  * アルバムのタイトルを取得
    271  */
    272 function db_album_get_c_album_subject4c_album_id($c_album_id)
    273 {
    274     $sql = 'SELECT subject FROM c_album WHERE c_album_id = ?';
    275     $params = array(intval($c_album_id));
    276 
    277     return db_get_one($sql, $params);
    278 }
    279 
    280 /*
    281 function db_album_get_c_album4id($c_album_id)
    282 {
    283     $sql = 'SELECT a.*,b.c_album_image_id,b.image_filename'.
    284             ' FROM c_album AS a,c_album_image AS b'.
    285             ' WHERE a.c_album_id = '.intval($c_album_id).' AND'.' b.c_album_id = '.intval($c_album_id);
    286            
    287     return db_get_all($sql, array());
    288 }
    289 */
    290 
    291 /*
    292 function db_album_image_get_c_album_image_ids4c_album_image_id($target_c_album_id)
    293 {
    294     $sql = 'SELECT c_album_image_id FROM c_album_image WHERE c_album_id = ?';
    295     $params = array(intval($target_c_album_id));
    296     return db_get_col($sql,$params);
    297 }
    298 */
    299 
    300 /**
    30174 * アルバム画像を取得
    30275 * @param int $c_album_image_id
     
    334107}
    335108
    336 
    337 /**
    338  * アルバムに登録されている画像リストを取得
    339  * @param int $c_album_id
    340  */
    341 function db_get_c_album_image_list4c_album_id($c_album_id)
    342 {
    343     $sql = 'SELECT * FROM c_album_image WHERE c_album_id = ?';
    344     $params = array(intval($c_album_id));
    345 
    346     return db_get_all($sql,$params);
    347 }
    348 
    349 //kazuki db_album_image_get_c_album_image4id()で代用可能
    350 /*
    351 function db_c_album_get_image_description4image_id($c_album_image_id)
    352 {
    353     $sql = 'SELECT image_description FROM c_album_image WHERE c_album_image_id = ?';
    354     $params = array(intval($c_album_image_id));
    355    
    356     return db_get_one($sql,$params);
    357 }
    358 */
    359 
    360109/**
    361110 * アルバムIDからアルバムに登録された画像を取得
     
    365114function db_album_get_c_album_page4id($c_album_id,$page_size=10,$page=0)
    366115{
    367     /*
    368     $sql = 'SELECT ab.*,i.c_album_image_id,i.image_filename,i.image_description'.
    369             ' FROM c_album AS ab,c_album_image AS i'.
    370             ' WHERE ab.c_album_id = '.intval($c_album_id).' AND'.' i.c_album_id = '.intval($c_album_id).' ORDER BY i.c_album_image_id ASC';
    371     */
    372    
    373116    $select = 'SELECT ab.*,i.c_album_image_id,i.image_filename,i.image_description';
    374117    $from  = ' FROM c_album AS ab,c_album_image AS i';
     
    379122   
    380123    $params = array(intval($c_album_id));
    381     //$list = db_get_all_page($sql, $page, $page_size, array());   
    382124    $list = db_get_all_limit($sql, $page_size * ($page - 1), $page_size, $params);
    383125   
     
    482224
    483225/*
    484 function db_get_friend4c_member_id($target_c_member_id)
    485 {
    486     $id = db_friend_c_member_id_list($target_c_member_id);
    487     $ids = implode(',',$id);
    488     $sql = 'SELECT c_member_id, nickname FROM c_member WHERE c_member_id IN ('.$ids.')';
    489    
    490     return db_get_all($sql,array());
    491 }
    492 */
    493 
    494 //kazuki 関数名が違うだけで同じ処理をしている関数(db_album_get_c_album4c_album_id)があるので削除
    495 /*
    496 function db_album_get_c_album_row4id($c_album_id)
    497 {
    498     $sql = 'SELECT * FROM c_album WHERE c_album_id = ?';
    499     return db_get_row($sql, array(intval($c_album_id)));
    500 }
    501 */
    502 
    503 function db_album_get_c_album_id4subject($subject,$c_member_id)
    504 {
    505     //todo:kazuki SQLの脆弱性きてんじゃない?
    506     $sql = 'SELECT c_album_id FROM c_album ' .
    507             'WHERE subject like '.'\'%'.strval($subject).'%\' AND c_member_id = ?';           //.'%'.$subject.'%';
    508    
    509     return db_get_row($sql, array(intval($c_member_id)));
    510 }
    511 
    512 /*
    513 function db_album_get_c_album_subject($target_c_member_id)
    514 {
    515     $sql = 'SELECT subject,c_album_id FROM c_album WHERE c_member_id = ? ORDER BY r_datetime DESC';
    516     $params = array(intval($target_c_member_id));
    517     return db_get_all($sql, $params);
    518 }
    519 */
    520 
    521 /**
    522  * メンバーIDから日記リストを最新順で取得
    523  *
    524  * @param int $c_member_id
    525  * @return array 日記リスト
    526  */
    527 /*
    528 function db_album_get_c_album_list4c_member_id($target_c_member_id, $count = 10, $u = null, $force = null)
    529 {
    530     static $is_recurred = false;  //再帰処理中かどうかの判定フラグ
    531 
    532     if (!$is_recurred) {  //function cacheのために再帰処理を行う
    533         $is_recurred = true;
    534         $funcargs = func_get_args();
    535         return pne_cache_recursive_call(OPENPNE_FUNCTION_CACHE_LIFETIME_FAST, __FUNCTION__, $funcargs);
    536     }
    537 
    538     $is_recurred = false;
    539 
    540     $pf_cond = db_album_public_flag_condition($target_c_member_id, $u, $force);
    541     $sql = 'SELECT * FROM c_album WHERE c_member_id = ?' . $pf_cond .
    542            ' ORDER BY r_datetime DESC';
    543     $params = array(intval($target_c_member_id));
    544     $arr = db_get_all_limit($sql, 0, $count, $params);
    545     foreach ($arr as $key => $value) {
    546         $arr[$key]['comment_count'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    547     }
    548     return $arr;
    549 }
    550 */
    551 
    552 //// c_album_comment
    553 
    554 /**
    555  * 日記のコメントリストを得る
    556  *
    557  * @param   int $c_album_id
    558  * @param   int $limit
    559  * @return  array 日記コメント+ニックネーム
    560  */
    561 /*
    562 function db_album_get_c_album_comment_list4c_album_id($c_album_id)
    563 {
    564     $sql = 'SELECT c_member.nickname, c_album_comment.*' .
    565         ' FROM c_album_comment LEFT JOIN c_member USING (c_member_id)' .
    566         ' WHERE c_album_id = ?' .
    567         ' ORDER BY c_album_comment.r_datetime';
    568     return db_get_all($sql, array(intval($c_album_id)));
    569 }
    570 */
    571 
    572 /**
    573  * 日記のコメントリスト(好きなID(複数))を取得
    574  *
    575  * @param   array $id_list
    576  * @param   int   $page
    577  * @param   int   $page_size
    578  * @param   bool  $desc  並び順を日時の新しい順にするかどうか
    579  * @return  日記コメント(+ニックネーム)リスト
    580  */
    581 /*
    582 function db_album_get_c_album_comment_list4id_list($id_list, $page = 1, $page_size= -1, $desc = false)
    583 {
    584     if (!count($id_list)) return array();
    585     if ($page_size < 0) {
    586         $page_size = count($id_list);
    587     }
    588     $e_id_list = implode(',', array_map('intval', (array)$id_list));
    589 
    590     $sql = 'SELECT * FROM c_album_comment' .
    591             ' WHERE c_album_comment_id IN ('.$e_id_list.')';
    592     if ($desc) {
    593         $sql .= ' ORDER BY r_datetime DESC';
    594     } else {
    595         $sql .= ' ORDER BY r_datetime';
    596     }
    597     $c_album_comment_list = db_get_all_page($sql, $page, $page_size);
    598 //        print "<pre>";
    599 //        echo "IN DATABASE<br>";
    600 //        print $page;
    601 //        print_r ($c_album_comment_list);
    602 //        echo "IN DATABASE<br>";
    603 //        print "</pre>";
    604     foreach ($c_album_comment_list as $key => $value) {
    605         $c_member = db_common_c_member4c_member_id_LIGHT($value['c_member_id']);
    606         $c_album_comment_list[$key]['nickname'] = $c_member['nickname'];
    607     }
    608 
    609     $sql = 'SELECT COUNT(*) FROM c_album_comment' .
    610         ' WHERE c_album_comment_id IN ('.$e_id_list.')';
    611     $total_num = db_get_one($sql);
    612 
    613     if ($total_num != 0) {
    614         $total_page_num = ceil($total_num / $page_size);
    615         if ($page >= $total_page_num) {
    616             $next = false;
    617         } else {
    618             $next = true;
    619         }
    620 
    621         if ($page <= 1) {
    622             $prev = false;
    623         } else {
    624             $prev = true;
    625         }
    626     }
    627 
    628     return array($c_album_comment_list, $prev , $next, $total_num);
    629 }
    630 */
    631 
    632 /**
    633  * 日記のコメント数を取得
    634  *
    635  * @param int $c_album_id
    636  * @return int コメント数
    637  */
    638 /*
    639 function db_album_count_c_album_comment4c_album_id($c_album_id)
    640 {
    641     $sql = 'SELECT COUNT(*) FROM c_album_comment WHERE c_album_id = ?';
    642     return db_get_one($sql, array(intval($c_album_id)));
    643 }
    644 */
    645 ////
    646 
    647 /**
    648  * あるメンバーの日記リストを取得
    649  *
    650  * @param int $c_member_id target c_member_id
    651  * @param int $page_size
    652  * @param int $page
    653  * @param int $u viewer's c_member_id
    654  * @return array 日記リスト
    655  */
    656 /*
    657 function p_fh_album_list_album_list4c_member_id($c_member_id, $page_size, $page, $u = null)
    658 {
    659     $pf_cond = db_album_public_flag_condition($c_member_id, $u);
    660 //    $s = 'SELECT min(c_album_image_id) FROM c_album_image WHERE c_album_image.c_album_id ='.$c_member_id;
    661 //    $re = db_get_one($s,array());
    662 //    echo $re."^&^&^&^&^&^&^&^&^&^&^";
    663     $sql = 'SELECT * FROM c_album'.$pf_cond.' ORDER BY r_datetime DESC';
    664     $params = array();
     226function p_fh_album_list_album_image_list4c_album_id($c_album_id, $page_size, $page)
     227{
     228    $sql = 'SELECT * FROM c_album_image WHERE c_album_id = ?';
     229    $params = array(intval($c_album_id));
    665230    $list = db_get_all_page($sql, $page, $page_size, $params);
    666    
    667     $sql1 = 'SELECT nickname FROM c_member WHERE c_member_id = ?';
    668    
    669     foreach ($list as $key => $c_album) {
    670         $list[$key]['num_comment'] = db_album_count_c_album_comment4c_album_id($c_album['c_album_id']);
    671         $list[$key]['nickname'] = db_get_one($sql1,$c_album['c_member_id']);
    672     }
    673 
    674     $sql = 'SELECT COUNT(*) FROM c_album ' . $pf_cond;
     231
     232   
     233    $sql = 'SELECT COUNT(*) FROM c_album_image WHERE c_album_id = ?';
    675234    $total_num = db_get_one($sql, $params);
    676235
     
    693252*/
    694253
    695 /**
    696  * 閲覧条件を考慮したアルバムリスト
    697  *
    698  **/
    699 function p_fh_album_list_album_list_public4c_member_id($c_member_id, $page_size, $page, $u = null)
    700 {
    701     //kazuki
    702     //todo:この処理を完成させる。
    703    
    704     $pf_cond = db_album_public_flag_condition($c_member_id, $u);
    705 //    $s = 'SELECT min(c_album_image_id) FROM c_album_image WHERE c_album_image.c_album_id ='.$c_member_id;
    706 //    $re = db_get_one($s,array());
    707 //    echo $re."^&^&^&^&^&^&^&^&^&^&^";
    708     $sql = 'SELECT * FROM c_album WHERE public_flag=\'public\' ORDER BY r_datetime DESC';
    709     $params = array();
    710     $list = db_get_all_page($sql, $page, $page_size, $params);
    711    
    712     $sql1 = 'SELECT nickname FROM c_member WHERE c_member_id = ?';
    713    
    714     foreach ($list as $key => $c_album) {
    715         $list[$key]['num_comment'] = db_album_count_c_album_comment4c_album_id($c_album['c_album_id']);
    716         $list[$key]['nickname'] = db_get_one($sql1,$c_album['c_member_id']);
    717     }
    718 
    719     $sql = 'SELECT COUNT(*) FROM c_album WHERE public_flag=\'public\'';
    720     $total_num = db_get_one($sql, $params);
    721 
    722     if ($total_num != 0) {
    723         $total_page_num =  ceil($total_num / $page_size);
    724         if ($page >= $total_page_num) {
    725             $next = false;
    726         } else {
    727             $next = true;
    728         }
    729 
    730         if ($page <= 1) {
    731             $prev = false;
    732         } else {
    733             $prev = true;
    734         }
    735     }
    736     return array($list, $prev, $next, $total_num);
    737 }
    738 
    739 function p_fh_album_list_album_image_list4c_album_id($c_album_id, $page_size, $page)
    740 {
    741     $sql = 'SELECT * FROM c_album_image WHERE c_album_id = ?';
    742     $params = array(intval($c_album_id));
    743     $list = db_get_all_page($sql, $page, $page_size, $params);
    744 
    745    
    746     $sql = 'SELECT COUNT(*) FROM c_album_image WHERE c_album_id = ?';
    747     $total_num = db_get_one($sql, $params);
    748 
    749     if ($total_num != 0) {
    750         $total_page_num =  ceil($total_num / $page_size);
    751         if ($page >= $total_page_num) {
    752             $next = false;
    753         } else {
    754             $next = true;
    755         }
    756 
    757         if ($page <= 1) {
    758             $prev = false;
    759         } else {
    760             $prev = true;
    761         }
    762     }
    763     return array($list, $prev, $next, $total_num);
    764 }
    765 
    766254//取得相册列表
     255/*
    767256function p_fh_album_list_fh_album_list4c_member_id($c_member_id, $page_size, $page,$u = null)
    768257{
     
    803292    return $temp;
    804293}
     294*/
    805295
    806296/*
     
    847337   
    848338    return array($list, $prev, $next, $total_num);
    849 }
    850 
    851 /*
    852 function db_common_album_monthly_calendar($year, $month, $c_member_id, $u = null)
    853 {
    854     include_once 'Calendar/Month/Weekdays.php';
    855     $Month = new Calendar_Month_Weekdays($year, $month, 0);
    856     $Month->build();
    857 
    858     $is_album_list = p_h_album_is_album_written_list4date($year, $month, $c_member_id, $u);
    859 
    860     $calendar = array();
    861     $week = 0;
    862     while ($Day = $Month->fetch()) {
    863         if ($Day->isFirst()) $week++;
    864 
    865         if ($Day->isEmpty()) {
    866             $calendar['days'][$week][] = array();
    867         } else {
    868             $day = $Day->thisDay();
    869             $item = array(
    870                 'day' => $day,
    871                 'is_diary' => in_array($day, $is_album_list),
    872             );
    873             $calendar['days'][$week][] = $item;
    874         }
    875     }
    876 
    877     // 最初に日記を書いた日
    878     $sql = 'SELECT r_datetime FROM c_album WHERE c_member_id = ? ORDER BY r_datetime';
    879     $first_datetime = db_get_one($sql, array(intval($c_member_id)));
    880 
    881     // 前の月、次の月
    882     $prev_month = $Month->prevMonth('timestamp');
    883     $this_month = $Month->thisMonth('timestamp');
    884     $next_month = $Month->nextMonth('timestamp');
    885 
    886     $ym = array(
    887         'disp_year'  => $year,
    888         'disp_month' => $month,
    889         'prev_year'  => null,
    890         'prev_month' => null,
    891         'next_year'  => null,
    892         'next_month' => null,
    893     );
    894     if ($first_datetime && strtotime($first_datetime) < $this_month) {
    895         $ym['prev_year'] = date('Y', $prev_month);
    896         $ym['prev_month'] = date('n', $prev_month);
    897     }
    898     if ($next_month < time()) {
    899         $ym['next_year'] = date('Y', $next_month);
    900         $ym['next_month'] = date('n', $next_month);
    901     }
    902     $calendar['ym'] = $ym;
    903 
    904     return $calendar;
    905 }
    906 */
    907 function count_members(){
    908     $sql = 'select max(c_member_id) from c_album';
    909     $params = array();
    910    
    911     return db_get_one($sql,$params);
    912 }
    913 
    914 function check_member_id($c_member_id){
    915     $sql = 'select c_member_id from c_album where c_member_id = ?';
    916     $params = array(intval($c_member_id));
    917     $result = db_get_row($sql,$params);
    918     if($result['c_member_id'])
    919         return true;
    920     else
    921         return false;
    922        
    923 }
    924 
    925 /**
    926  * フレンドの最新日記リスト
    927  */
    928 function p_h_album_list_friend_h_album_list_friend4c_member_id($c_member_id, $page_size, $page)
    929 {
    930     $friends = db_friend_c_member_id_list($c_member_id, true);
    931     $ids = implode(',', array_map('intval', $friends));
    932 
    933     $hint = db_mysql_hint('USE INDEX (r_datetime_c_member_id, r_datetime)');
    934     $sql = 'SELECT * FROM c_album' . $hint .
    935             ' WHERE c_member_id IN (' . $ids . ')' .
    936             ' AND public_flag <> \'private\'' .
    937             ' ORDER BY c_album.r_datetime DESC';
    938 
    939     $lst = db_get_all_page($sql, $page, $page_size);
    940 
    941     foreach ($lst as $key=>$value) {
    942         $lst[$key]['count_comments'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    943         $lst[$key]['c_member'] = db_common_c_member4c_member_id($value['c_member_id']);
    944     }
    945 
    946     $sql = 'SELECT count(*) FROM c_album' .
    947            ' WHERE c_member_id IN (' . $ids . ')' .
    948            ' AND public_flag <> \'private\'';
    949     $total_num = db_get_one($sql, $params);
    950 
    951     if ($total_num != 0) {
    952         $total_page_num =  ceil($total_num / $page_size);
    953         if ($page >= $total_page_num) {
    954             $next = false;
    955         } else {
    956             $next = true;
    957         }
    958 
    959         if ($page <= 1) {
    960             $prev = false;
    961         } else {
    962             $prev = true;
    963         }
    964     }
    965 
    966     return array($lst, $prev, $next, $total_num);
    967 }
    968 
    969 /**
    970  * 未読コメントのある日記の数を数える
    971  *
    972  * @param int $c_member_id
    973  * @return int 未読日記数
    974  */
    975 function p_h_album_count_c_album_not_is_read4c_member_id($c_member_id)
    976 {
    977     $sql = 'SELECT COUNT(*) FROM c_album WHERE c_member_id = ? AND is_checked = 0';
    978     $params = array(intval($c_member_id));
    979     return db_get_one($sql, $params);
    980 }
    981 
    982 function db_count_c_album_image($c_album_id)
    983 {
    984     $sql = 'SELECT COUNT(*) FROM c_album_image WHERE c_album_id = ?';
    985     $params = array(intval($c_album_id));
    986     return db_get_one($sql, $params);
    987 }
    988 
    989 /**
    990  * 未読コメントのある日記のうちもっとも古い日記IDを返す
    991  *
    992  * @param int $c_member_id
    993  * @return int c_album_id
    994  */
    995 function p_h_album_c_album_first_album_read4c_member_id($c_member_id)
    996 {
    997     $sql = 'SELECT c_album_id FROM c_album WHERE c_member_id = ? AND is_checked = 0 ORDER BY r_datetime';
    998     $params = array(intval($c_member_id));
    999     return db_get_one($sql, $params);
    1000 }
    1001 
    1002 /**
    1003  * フレンド最新日記リスト取得
    1004  * 日記公開範囲を考慮
    1005  *
    1006  * @param   int $c_member_id
    1007  * @param   int $limit
    1008  * @return  array_of_array  (c_album.*, nickname)
    1009  */
    1010 function p_h_home_c_album_friend_list4c_member_id($c_member_id, $limit)
    1011 {
    1012     static $is_recurred = false;  //再帰処理中かどうかの判定フラグ
    1013 
    1014     if (!$is_recurred) {  //function cacheのために再帰処理を行う
    1015         $is_recurred = true;
    1016         $funcargs = func_get_args();
    1017         return pne_cache_recursive_call(OPENPNE_FUNCTION_CACHE_LIFETIME_FAST, __FUNCTION__, $funcargs);
    1018     }
    1019 
    1020     $is_recurred = false;
    1021 
    1022     $friends = db_friend_c_member_id_list($c_member_id, true);
    1023     $ids = implode(',', array_map('intval', $friends));
    1024 
    1025     $hint = db_mysql_hint('USE INDEX (r_datetime_c_member_id, r_datetime)');
    1026     $sql = 'SELECT * FROM c_album' . $hint .
    1027             ' WHERE c_member_id IN (' . $ids . ')' .
    1028             ' AND public_flag <> \'private\'' .
    1029             ' ORDER BY c_album.r_datetime DESC';
    1030 
    1031     $c_album_friend_list = db_get_all_limit($sql, 0, $limit);
    1032 
    1033     foreach ($c_album_friend_list as $key => $value) {
    1034         $c_member = db_common_c_member4c_member_id_LIGHT($value['c_member_id']);
    1035         $c_album_friend_list[$key]['nickname'] = $c_member['nickname'];
    1036         $c_album_friend_list[$key]['count_comments'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    1037     }
    1038     return $c_album_friend_list;
    1039 }
    1040 
    1041 /**
    1042  * 日記コメント記入履歴取得
    1043  *
    1044  * @param   int $c_member_id
    1045  * @param   int $limit
    1046  * @return  array_of_array  (c_album.*, nickname)
    1047  */
    1048 /*
    1049 function p_h_home_c_album_my_comment_list4c_member_id($c_member_id, $limit)
    1050 {
    1051     static $is_recurred = false;  //再帰処理中かどうかの判定フラグ
    1052 
    1053     if (!$is_recurred) {  //function cacheのために再帰処理を行う
    1054         $is_recurred = true;
    1055         $funcargs = func_get_args();
    1056         return pne_cache_recursive_call(OPENPNE_FUNCTION_CACHE_LIFETIME_FAST, __FUNCTION__, $funcargs);
    1057     }
    1058 
    1059     $is_recurred = false;
    1060 
    1061     $date = date('Y-m-d 00:00:00', strtotime('-15 days'));
    1062 
    1063     $blocked = db_member_access_block_list4c_member_id_to($c_member_id);
    1064     $blocked[] = $c_member_id;
    1065     $except_ids = implode(',', $blocked);
    1066 
    1067     $sql = 'SELECT c_album_comment.c_album_id' .
    1068             ' FROM c_album_comment INNER JOIN c_album USING (c_album_id)' .
    1069             ' WHERE c_album_comment.c_member_id = ?' .
    1070             ' AND c_album_comment.r_datetime > ?' .
    1071             ' AND c_album.c_member_id NOT IN (' . $except_ids . ')' .
    1072             ' AND c_album.public_flag <> \'private\'';
    1073     $params = array(intval($c_member_id), $date);
    1074     $c_album_id_list = db_get_col($sql, $params);
    1075     $c_album_id_list = array_unique($c_album_id_list);
    1076     if (!$c_album_id_list) {
    1077         return array();
    1078     }
    1079 
    1080     $ids = implode(',', $c_album_id_list);
    1081     $sql = 'SELECT c_album_id, MAX(r_datetime) as maxdate' .
    1082            ' FROM c_album_comment' .
    1083            ' WHERE c_album_id IN (' . $ids . ')' .
    1084            ' GROUP BY c_album_id' .
    1085            ' ORDER BY maxdate DESC';
    1086     $list = db_get_assoc_limit($sql, 0, $limit);
    1087 
    1088     $result = array();
    1089     foreach ($list as $c_album_id => $r_datetime) {
    1090         $item = db_album_get_c_album4id($c_album_id);
    1091         if ($item['public_flag'] == 'friend' && !db_friend_is_friend($c_member_id, $item['c_member_id'])) {
    1092             continue;
    1093         }
    1094         $item += db_common_c_member4c_member_id_LIGHT($item['c_member_id']);
    1095         $item['r_datetime'] = $r_datetime;
    1096         $item['num_comment'] = db_album_count_c_album_comment4c_album_id($c_album_id);
    1097         $result[] = $item;
    1098     }
    1099     return $result;
    1100 }
    1101 */
    1102 
    1103 function p_h_album_comment_list_c_album_my_comment_list4c_member_id($c_member_id, $page, $page_size)
    1104 {
    1105     $blocked = db_member_access_block_list4c_member_id_to($c_member_id);
    1106     $blocked[] = $c_member_id;
    1107     $except_ids = implode(',', $blocked);
    1108 
    1109     $friends = db_friend_c_member_id_list($c_member_id);
    1110     $friend_ids = implode(',', $friends);
    1111 
    1112     $sql = 'SELECT d.c_album_id' .
    1113             ', d.subject' .
    1114             ', d.c_member_id' .
    1115             ', MAX(dc.r_datetime) AS r_datetime' .
    1116             ', COUNT(DISTINCT dc.c_album_comment_id) AS num_comment' .
    1117         ' FROM c_album AS d' .
    1118             ' INNER JOIN c_album_comment AS dc USING (c_album_id)' .
    1119             ', c_album_comment AS mydc' .
    1120         ' WHERE mydc.c_member_id = ?' .
    1121             ' AND mydc.c_album_id = d.c_album_id' .
    1122             ' AND mydc.c_member_id <> d.c_member_id' .
    1123             ' AND d.c_member_id NOT IN (' . $except_ids . ')' .
    1124             ' AND (d.public_flag = \'public\' OR (d.public_flag = \'friend\' AND d.c_member_id IN (' . $friend_ids . ')))' .
    1125         ' GROUP BY dc.c_album_id' .
    1126         ' ORDER BY r_datetime DESC';
    1127 
    1128     $params = array(intval($c_member_id));
    1129     $list = db_get_all_page($sql, $page, $page_size, $params);
    1130 
    1131     foreach ($list as $key => $value) {
    1132         $list[$key] += db_common_c_member4c_member_id_LIGHT($value['c_member_id']);
    1133     }
    1134 
    1135     $sql = 'SELECT COUNT(DISTINCT d.c_album_id)' .
    1136         ' FROM c_album AS d' .
    1137             ' INNER JOIN c_album_comment AS dc USING (c_album_id)' .
    1138             ', c_album_comment AS mydc' .
    1139         ' WHERE mydc.c_member_id = ?' .
    1140             ' AND mydc.c_album_id = d.c_album_id' .
    1141             ' AND mydc.c_member_id <> d.c_member_id' .
    1142             ' AND d.c_member_id NOT IN (' . $except_ids . ')' .
    1143             ' AND (d.public_flag = \'public\' OR (d.public_flag = \'friend\' AND d.c_member_id IN (' . $friend_ids . ')))';
    1144     $total_num = db_get_one($sql, $params);
    1145 
    1146     $is_prev = false;
    1147     $is_next = false;
    1148     if ($total_num) {
    1149         $is_prev = (bool)($page > 1);
    1150         $is_next = (bool)($page < ceil($total_num / $page_size));
    1151     }
    1152     return array($list, $is_prev, $is_next, $total_num);
    1153 }
    1154 
    1155 /**
    1156  * あるメンバーの指定された年月日の日記のリストを得る
    1157  */
    1158 /*
    1159 function p_fh_album_list_album_list_date4c_member_id($c_member_id, $page_size, $page, $year, $month, $day=0 ,$u = null)
    1160 {
    1161     if ($day) {
    1162         $s_date = date('Y-m-d H:i:s', mktime(0, 0, 0, $month, $day, $year));
    1163         $e_date = date('Y-m-d H:i:s', mktime(0, 0, 0, $month, $day+1, $year));
    1164     } else {
    1165         $s_date = date('Y-m-d H:i:s', mktime(0, 0, 0, $month, 1, $year));
    1166         $e_date = date('Y-m-d H:i:s', mktime(0, 0, 0, $month+1, 1, $year));
    1167     }
    1168 
    1169     $pf_cond = db_album_public_flag_condition($c_member_id, $u);
    1170     $where = ' WHERE c_member_id = ? AND c_album.r_datetime >= ? AND c_album.r_datetime < ?';
    1171     $sql = 'SELECT * FROM c_album' .
    1172             $where .                                //. $pf_cond .
    1173             ' ORDER BY r_datetime DESC';
    1174     $params = array(intval($c_member_id), $s_date, $e_date);
    1175     $list = db_get_all_limit($sql, $page_size * ($page - 1), $page_size, $params);
    1176    
    1177    
    1178    
    1179     foreach ($list as $key => $c_album) {
    1180         $list[$key]['num_comment'] = db_album_count_c_album_comment4c_album_id($c_album['c_album_id']);
    1181     }
    1182 
    1183     $sql = 'SELECT COUNT(*) FROM c_album_image' . $where;
    1184     $total_num = db_get_one($sql, $params);
    1185 
    1186     if ($total_num != 0) {
    1187         $total_page_num =  ceil($total_num / $page_size);
    1188         if ($page >= $total_page_num) {
    1189             $next = false;
    1190         } else {
    1191             $next = true;
    1192         }
    1193         if ($page <= 1) {
    1194             $prev = false;
    1195         } else {
    1196             $prev = true;
    1197         }
    1198     }
    1199     return array($list , $prev , $next, $total_num);
    1200 }
    1201 */
    1202 /**
    1203  * 日記ページの「各月の日記」用
    1204  *
    1205  * 日記を最初に書いた月からスタートしてみる
    1206  */
    1207 function p_fh_album_list_date_list4c_member_id($c_member_id)
    1208 {
    1209     $sql = "SELECT r_datetime FROM c_album" .
    1210         " WHERE c_member_id = ?" .
    1211         " ORDER BY r_datetime";
    1212     $params = array(intval($c_member_id));
    1213     if (!$first_datetime = db_get_one($sql, $params)) {
    1214         return array();
    1215     }
    1216 
    1217     $start_date = getdate(strtotime($first_datetime));
    1218     $end_date =  getdate();
    1219 
    1220     $date = array();
    1221     $year = $start_date['year'];
    1222     $month = $start_date['mon'];
    1223     while (1) {
    1224         $date[] =  array(
    1225             'year' => $year,
    1226             'month' => $month,
    1227         );
    1228 
    1229         if ($end_date['year'] <= $year
    1230             && $end_date['mon'] <= $month) {
    1231             break;
    1232         }
    1233 
    1234         $month++;
    1235         if ($month > 12) {
    1236             $month = 1;
    1237             $year++;
    1238         }
    1239     }
    1240     return array_reverse($date);
    1241 }
    1242 
    1243 //c_member_id から自分の日記についてるコメントID(複数)を取得
    1244 function p_fh_album_c_album_comment_id_list4c_member_id($c_member_id)
    1245 {
    1246     $sql = "SELECT cdc.c_album_comment_id FROM c_album as cd,c_album_comment as cdc" .
    1247         " WHERE cd.c_member_id = ?".
    1248         " AND cd.c_album_id = cdc.c_album_id";
    1249     $params = array(intval($c_member_id));
    1250     return db_get_col($sql, $params);
    1251 }
    1252 
    1253 /**
    1254  * 年月 から日記のある日(複数)を取得
    1255  */
    1256 function p_fh_album_list_calendar_list4c_member_id($year, $month, $c_member_id)
    1257 {
    1258     $sql = "SELECT cdc.c_album_comment_id FROM c_album as cd,c_album_comment as cdc" .
    1259         " WHERE cd.c_member_id = ?".
    1260         " AND cd.c_album_id = cdc.c_album_id";
    1261     $params = array(intval($c_member_id));
    1262     return db_get_col($sql, $params);
    1263339}
    1264340
     
    1324400
    1325401/**
    1326  * 指定された年月に日記を書いている日のリストを返す
    1327  */
    1328 /*
    1329 function p_h_album_is_album_written_list4date($year, $month, $c_member_id, $u = null)
    1330 {
    1331     include_once 'Date/Calc.php';
    1332 
    1333     $pf_cond = db_album_public_flag_condition($c_member_id, $u);
    1334     $sql = 'SELECT DISTINCT DAYOFMONTH(r_datetime) FROM c_album' .
    1335            ' WHERE c_member_id = ? AND r_datetime >= ? AND r_datetime < ?' . $pf_cond;
    1336 
    1337     $date_format = '%Y-%m-%d 00:00:00';
    1338     $thismonth = Date_Calc::beginOfMonth($month, $year, $date_format);
    1339     $nextmonth = Date_Calc::beginOfNextMonth(0, $month, $year, $date_format);
    1340 
    1341     $params = array(intval($c_member_id), $thismonth, $nextmonth);
    1342 
    1343     return db_get_col($sql, $params);
    1344 }
    1345 */
    1346 
    1347 /**
    1348  * 日記コメント情報をIDから取得
    1349  *
    1350  * @param   int $c_album_comment_id
    1351  * @return array
    1352  *              c_album_comemnt.*
    1353  *              c_album.c_member_id AS c_member_id_author
    1354  */
    1355 function _do_c_album_comment4c_album_comment_id($c_album_comment_id)
    1356 {
    1357     $sql = "SELECT dc.*, d.c_member_id AS c_member_id_author";
    1358     $sql .= " FROM c_album_comment AS dc, c_album AS d";
    1359     $sql .= " WHERE dc.c_album_comment_id = ?";
    1360     $sql .= " AND dc.c_album_id = d.c_album_id";
    1361     $params = array(intval($c_album_comment_id));
    1362     return db_get_row($sql, $params);
    1363 }
    1364 
    1365 /**
    1366  * ターゲットメンバの最新日記のリストを返す
    1367  */
    1368 function k_p_f_home_c_album_list4c_member_id($c_member_id, $limit)
    1369 {
    1370     //日記リスト
    1371     $sql = "SELECT c_album_id, r_date, subject ,image_filename_1";
    1372     $sql .= " FROM c_album";
    1373     $sql .= " WHERE c_member_id = ?";
    1374     $sql .= " ORDER BY r_date DESC";
     402 * フレンドの最新アルバムリスト
     403 */
     404function k_p_h_album_list_friend_h_album_list_friend4c_member_id($c_member_id, $page_size, $page)
     405{
     406    $from = "c_album, c_friend";
     407    $where = "c_friend.c_member_id_from = ?" .
     408            " AND c_album.c_member_id = c_friend.c_member_id_to";
     409
     410    $sql = "SELECT c_album.* FROM {$from} WHERE {$where}" .
     411            " ORDER BY c_album.r_datetime DESC";
    1375412    $params = array(intval($c_member_id));
    1376     $c_album_list = db_get_all_limit($sql, 0, $limit, $params);
    1377 
    1378     //コメント数
    1379     foreach ($c_album_list as $key => $value) {
    1380         $c_album_id = $value['c_album_id'];
    1381 
    1382         $sql = "SELECT COUNT(*) ";
    1383         $sql .= "FROM c_album_comment ";
    1384         $sql .= "WHERE c_album_id = ?";
    1385         $params = array(intval($c_album_id));
    1386         $c_album_list[$key]['count_comment'] = db_get_one($sql, $params);
    1387     }
    1388     return $c_album_list;
    1389 }
    1390 
    1391 /**
    1392  * 最新日記リストを取得。
    1393  * 取得範囲を指定できる。
    1394  */
    1395 function k_p_fh_album_list_c_album_list4c_member_id($c_member_id, $page_size, $page)
    1396 {
    1397     $sql = 'SELECT * FROM c_album WHERE c_member_id = ? ORDER BY r_datetime DESC';
    1398     $params = array(intval($c_member_id));
    1399     $c_album_list = db_get_all_page($sql, $page, $page_size, $params);
    1400 
    1401     foreach ($c_album_list as $key => $value) {
    1402         $c_album_list[$key]['count_comment'] =
    1403             db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    1404     }
    1405 
    1406     $sql = 'SELECT COUNT(*) FROM c_album WHERE c_member_id = ?';
     413    $lst = db_get_all_page($sql, $page, $page_size, $params);
     414
     415    foreach ($lst as $key=>$value) {
     416        //$lst[$key]['count_comments'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
     417        $lst[$key]['c_member'] = db_common_c_member4c_member_id($value['c_member_id']);
     418    }
     419
     420    $sql = "SELECT count(*) FROM {$from} WHERE {$where}";
    1407421    $total_num = db_get_one($sql, $params);
    1408422
     
    1414428            $next = true;
    1415429        }
     430
    1416431        if ($page <= 1) {
    1417432            $prev = false;
     
    1420435        }
    1421436    }
    1422     return array($c_album_list , $prev , $next);
    1423 }
    1424 
    1425 /**
    1426  * 日記へのコメントリストを取得
    1427  */
    1428 function k_p_fh_album_c_album_comment_list4c_album_id($c_album_id, $page_size, $page)
    1429 {
    1430     $sql = 'SELECT * FROM c_album_comment WHERE c_album_id = ? ORDER BY r_datetime DESC';
    1431     $params = array(intval($c_album_id));
    1432     $c_album_comment_list = db_get_all_page($sql, $page, $page_size, $params);
    1433 
    1434     foreach ($c_album_comment_list as $key => $value) {
    1435         $c_member = db_common_c_member4c_member_id_LIGHT($value['c_member_id']);
    1436         $c_album_comment_list[$key]['nickname'] = $c_member['nickname'];
    1437     }
    1438 
    1439     $sql = "SELECT COUNT(*) FROM c_album_comment WHERE c_album_id = ?";
    1440     $params = array(intval($c_album_id));
    1441     $total_num = db_get_one($sql, $params);
    1442 
    1443     if ($total_num > 0) {
    1444         $total_page_num =  ceil($total_num / $page_size);
    1445         if ($page >= $total_page_num) {
    1446             $next = false;
    1447         } else {
    1448             $next = true;
    1449         }
    1450         if ($page <= 1) {
    1451             $prev = false;
    1452         } else {
    1453             $prev = true;
    1454         }
    1455     }
    1456     return array($c_album_comment_list , $prev , $next, $total_num, $total_page_num);
    1457 }
    1458 
    1459 /**
    1460  * 日記IDからその日記を書いたメンバIDとニックネームと日記公開範囲を得る
    1461  */
    1462 function k_p_fh_album_c_member4c_album_id($c_album_id)
    1463 {
    1464     $sql = "SELECT cm.c_member_id, cm.nickname,cm. public_flag_album ";
    1465     $sql .= " FROM c_member AS cm, c_album AS cd ";
    1466     $sql .= " WHERE cd.c_album_id = ?";
    1467     $sql .= " AND cm.c_member_id=cd.c_member_id";
    1468     $params = array(intval($c_album_id));
    1469     return db_get_row($sql, $params);
    1470 }
    1471 
    1472 /**
    1473  * フレンドの最新日記リスト
    1474  */
    1475 function k_p_h_album_list_friend_h_album_list_friend4c_member_id($c_member_id, $page_size, $page)
    1476 {
    1477     $from = "c_album, c_friend";
    1478     $where = "c_friend.c_member_id_from = ?" .
    1479             " AND c_album.c_member_id = c_friend.c_member_id_to";
    1480 
    1481     $sql = "SELECT c_album.* FROM {$from} WHERE {$where}" .
    1482             " ORDER BY c_album.r_datetime DESC";
    1483     $params = array(intval($c_member_id));
    1484     $lst = db_get_all_page($sql, $page, $page_size, $params);
    1485 
    1486     foreach ($lst as $key=>$value) {
    1487         $lst[$key]['count_comments'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    1488         $lst[$key]['c_member'] = db_common_c_member4c_member_id($value['c_member_id']);
    1489     }
    1490 
    1491     $sql = "SELECT count(*) FROM {$from} WHERE {$where}";
    1492     $total_num = db_get_one($sql, $params);
    1493 
    1494     if ($total_num != 0) {
    1495         $total_page_num =  ceil($total_num / $page_size);
    1496         if ($page >= $total_page_num) {
    1497             $next = false;
    1498         } else {
    1499             $next = true;
    1500         }
    1501 
    1502         if ($page <= 1) {
    1503             $prev = false;
    1504         } else {
    1505             $prev = true;
    1506         }
    1507     }
    1508437
    1509438    return array($lst, $prev, $next, $total_num);
    1510439}
    1511440
    1512 //--- album
    1513 
    1514 function check_default_album_exist($c_member_id)
    1515 {
    1516     $sql = 'SELECT default_flag FROM c_album_default_flag WHERE c_member_id = ?';
    1517     $params = array(intval($c_member_id));
    1518     $reault = db_get_one($sql,$params);
    1519 //    print_r ($reault);
    1520 
    1521     if(empty($reault)){
    1522         $sql1 = 'INSERT INTO c_album_default_flag VALUES('.$c_member_id.','.intval(1).')';
    1523         db_query($sql1,array());
    1524 //        echo $sql1;
    1525         return 0;
    1526     }else{
    1527         return 1;
    1528     }
    1529    
    1530 }
    1531 
    1532 
    1533441/**
    1534442 * アルバムを追加
    1535443 */
    1536 //function db_album_insert_c_album($c_member_id,$c_commu_id, $subject, $description,$is_shown, $public_flag, $album_pwd)
    1537444function db_album_insert_c_album($c_member_id, $subject, $description,$public_flag)
    1538445{
    1539 //    function cacheの削除
    1540 //    pne_cache_drop('db_album_get_c_album_list4c_member_id', $c_member_id, 5);
    1541 
    1542446    $data = array(
    1543447        'c_member_id' => intval($c_member_id),
    1544         //'c_commu_id' => intval($c_commu_id),
    1545448        'subject' => $subject,
    1546449        'description' => $description,
    1547         //'is_shown' => $is_shown,
    1548450        'public_flag' => $public_flag,
    1549451        'r_datetime' => db_now(),
    1550         'r_date' => db_now(),
    1551         //'is_checked' => 1,
    1552         //'default_flag' => 1,
    1553     );
    1554    
    1555     /*
    1556     if($album_pwd)
    1557     {
    1558         $data['album_pwd'] = $album_pwd;
    1559     }
    1560     */
     452    );
    1561453   
    1562454    return db_insert('c_album', $data);
     
    1584476    $data = array(
    1585477        'image_description' => $image_description,
    1586 //        'r_datetime' => db_now(),
    1587478    );
    1588479    if ($image_filename) $data['image_filename'] = $image_filename;
     
    1593484   
    1594485    return db_update('c_album_image', $data, $where);
    1595    
     486}
     487
     488/**
     489 * アルバムの情報を更新
     490 */
     491function db_album_update_c_album_cover($c_album_id,$subject,$description,$album_cover_image,$public_flag)
     492{
     493    $data = array(
     494        'subject' => $subject,
     495        'description' => $description,
     496        'public_flag' => $public_flag,
     497    );
     498    if ($album_cover_image) $data['album_cover_image'] = $album_cover_image;
     499
     500    $where = array(
     501        'c_album_id' => intval($c_album_id),
     502    );
     503
     504    return db_update('c_album', $data, $where);
    1596505}
    1597506
     
    1609518    );
    1610519    return db_update('c_album', $data, $where);
    1611    
    1612 }
    1613 
    1614 /**
    1615  * 日記を編集
    1616  */
     520}
     521
     522/**
     523 * アルバムを編集
     524 */
     525/*
    1617526function db_album_insert_c_album_image($c_album_image_id,$image_filename_1 = '',$image_description)
    1618527{
    1619     //function cacheの削除
    1620 //    $c_album = db_album_get_c_album4id($c_album_id);
    1621 //    pne_cache_drop('db_album_get_c_album_list4c_member_id', $c_album['c_member_id'], 5);
    1622 
    1623528    $data = array(
    1624529            'c_album_image_id'=>$c_album_image_id,
     
    1630535    $where = array(
    1631536        'c_album_image_id' => intval($c_album_image_id),
    1632        
    1633     );
     537    );
     538
    1634539    return db_insert('c_album_image', $data, $where);
    1635540}
    1636 
    1637 
    1638 
    1639 function db_insert_c_album_image($c_album_id,$image_filename_1 = '',$image_description)
    1640 {
    1641     //function cacheの削除
    1642 //    $c_album = db_album_get_c_album4id($c_album_id);
    1643 //    pne_cache_drop('db_album_get_c_album_list4c_member_id', $c_album['c_member_id'], 5);
    1644 
     541*/
     542
     543/**
     544 * c_album_imageの新規登録
     545 * @param int $c_album_id
     546 * @param string $image_filename
     547 * @param string $image_description
     548 */
     549function db_insert_c_album_image($c_album_id, $image_filename, $image_description)
     550{
    1645551    $data = array(
    1646552            'c_album_id'=>$c_album_id,
     
    1648554            'r_datetime' => db_now(),
    1649555    );
    1650     if ($image_filename_1) $data['image_filename'] = $image_filename_1;
     556    if ($image_filename) $data['image_filename'] = $image_filename;
    1651557       
    1652558    return db_insert('c_album_image', $data);
     
    1654560
    1655561/**
    1656  * アルバムの削除
    1657  * 画像も削除
     562 * アルバムの削除、画像も削除
    1658563 * @param int $c_album_id
    1659564 */
     
    1664569    pne_cache_drop('db_album_get_c_album_list4c_member_id', $c_album_image['c_member_id'], 5);
    1665570
    1666    // アルバムに登録された画像
     571    //アルバムに登録された画像
    1667572    foreach($c_album_image as $key=>$value){
    1668         //image_data_delete($c_album[$key]['image_filename']);
    1669573        db_album_image_data_delete($c_album_image[$key]['image_filename']);
    1670574    }
     
    1676580    }
    1677581
    1678     // コメント
    1679     /*
    1680     $sql = 'SELECT image_filename_1, image_filename_2, image_filename_3 FROM c_album_comment WHERE c_album_id =?';
    1681     $params = array(intval($c_album_id));
    1682     $comment_images = db_get_all($sql, $params);
    1683     */
    1684 
    1685     //カテゴリ
    1686     /*
    1687     db_album_category_delete_c_album_category_album($c_album_id);
    1688 
    1689     foreach ($comment_images as $value) {
    1690         image_data_delete($value['image_filename_1']);
    1691         image_data_delete($value['image_filename_2']);
    1692         image_data_delete($value['image_filename_3']);
    1693     }
    1694     */
    1695582    $params = array(intval($c_album_id));
    1696583   
     
    1704591
    1705592    return;
    1706 
    1707     /*
    1708     $sql = 'DELETE FROM c_album_comment WHERE c_album_id = ?';
    1709     db_query($sql, $params);
    1710     */
    1711593}
    1712594
     
    1718600    $sql = 'DELETE FROM c_album_image WHERE c_album_image_id = ?';
    1719601    $params = array(intval($c_album_image_id));
     602
    1720603    return db_query($sql, $params);
    1721 //    $data = array(
    1722 //        'image_filename' => '',
    1723 //    );
    1724 //    $where = 'c_album_image_id = '.intval($c_album_image_id);
    1725 //    return db_update('c_album_image', $data, $where);
    1726 }
    1727 
    1728 /**
    1729  * 日記に画像を追加する
    1730  */
    1731 function db_album_update_c_album_image_filename($c_album_id, $image_filename, $image_num)
    1732 {
    1733     $data = array(
    1734         'image_filename_'.intval($image_num) => $image_filename,
    1735     );
    1736     $where = 'c_album_id = '.intval($c_album_id);
    1737     return db_update('c_album', $data, $where);
    1738 }
    1739 
    1740 /**
    1741  * 日記の未読/既読を変更
    1742  * c_album.is_checkedを更新
    1743  */
    1744 //kazuki diaryを参考にしたのでアルバムに未読フラグを追加したと思われる
    1745 /*
    1746 function db_album_update_c_album_is_checked($c_album_id, $value)
    1747 {
    1748     $data = array(
    1749         'is_checked' => (bool)$value,
    1750     );
    1751     $where = 'c_album_id = '.intval($c_album_id);
    1752     return db_update('c_album', $data, $where);
    1753 }
    1754 */
    1755 //--- album_comment
    1756 
    1757 /**
    1758  * 日記コメント追加
    1759  *
    1760  * @param  int    $c_member_id
    1761  * @param  int    $c_album_id
    1762  * @param  string $body
    1763  * @return int    insert_id
    1764  */
    1765 function db_album_insert_c_album_comment($c_member_id, $c_album_id, $body)
    1766 {
    1767     //function cache削除
    1768     pne_cache_drop('p_h_home_c_album_my_comment_list4c_member_id', $c_member_id, 5);
    1769 
    1770     $data = array(
    1771         'c_member_id' => intval($c_member_id),
    1772         'c_album_id' => intval($c_album_id),
    1773         'body' => $body,
    1774         'r_datetime' => db_now(),
    1775     );
    1776     return db_insert('c_album_comment', $data);
    1777 }
    1778 
    1779 /**
    1780  * 日記コメント用画像追加
    1781  */
    1782 function db_album_insert_c_album_comment_images($c_album_comment_id, $image_filename_1 = '', $image_filename_2 = '', $image_filename_3 = '')
    1783 {
    1784     $data = array();
    1785     if ($image_filename_1) $data['image_filename_1'] = $image_filename_1;
    1786     if ($image_filename_2) $data['image_filename_2'] = $image_filename_2;
    1787     if ($image_filename_3) $data['image_filename_3'] = $image_filename_3;
    1788 
    1789     $where = array(
    1790         'c_album_comment_id' => intval($c_album_comment_id),
    1791     );
    1792     return db_update('c_album_comment', $data, $where);
    1793 }
    1794 
    1795 /**
    1796  * 日記コメント削除
    1797  *
    1798  * @param   int $c_album_comment_id
    1799  * @param   int $u  : 削除しようとしている人の c_member_id
    1800  */
    1801 function db_album_delete_c_album_comment($c_album_comment_id, $u)
    1802 {
    1803     $dc = _do_c_album_comment4c_album_comment_id($c_album_comment_id);
    1804     if ($dc['c_member_id'] != $u && $dc['c_member_id_author'] != $u) {
    1805         return false;
    1806     }
    1807 
    1808     image_data_delete($dc['image_filename_1']);
    1809     image_data_delete($dc['image_filename_2']);
    1810     image_data_delete($dc['image_filename_3']);
    1811 
    1812     $sql = 'DELETE FROM c_album_comment WHERE c_album_comment_id = ?';
    1813     $params = array(intval($c_album_comment_id));
    1814     return db_query($sql, $params);
    1815 }
    1816 
    1817 // 日記公開範囲の一括設定をする
    1818 function db_album_update_public_flag_album_all($c_member_id, $public_flag)
    1819 {
    1820     $data = array(
    1821         'public_flag' => $public_flag,
    1822     );
    1823 
    1824     $where = array(
    1825         'c_member_id' => intval($c_member_id),
    1826     );
    1827     return db_update('c_album', $data, $where);
    1828 }
    1829 
    1830 /*
    1831 function db_member_check_album_exist($c_member_id)
    1832 {
    1833     $sql = 'SELECT c_album_id FROM c_album WHERE c_member_id = ?';
    1834     $params = array(intval($c_member_id));
    1835     return db_get_row($sql, $params);
    1836 }
    1837 */
    1838 
    1839 function db_update_c_album_r_datetime($c_album_id)
    1840 {
    1841     $data = array(
    1842             'r_datetime' => db_now()
    1843     );
    1844    
    1845     $where = array('c_album_id' => intval($c_album_id));
    1846     return db_update('c_album',$data,$where);
    1847 }
    1848 
    1849 function monitor_album_list($keyword,$page_size,$page)
    1850 {
    1851 
    1852     $page = intval($page);
    1853     $page_size = intval($page_size);
    1854    
    1855     $where = " where 1 ";
    1856 
    1857     if ($keyword) {
    1858         //全角空白を半角に統一
    1859         $keyword = str_replace(" ", " ", $keyword);
    1860         $keyword_list = explode(" ", $keyword);
    1861            
    1862         for($i=0;$i < count($keyword_list);$i++) {
    1863             $keyword = check_search_word( $keyword_list[$i] );
    1864                
    1865             $where .= " and (c_album.subject like ? ";
    1866             $where .= " or c_album.description like ? ) ";
    1867             $params[]="%$keyword%";
    1868             $params[]="%$keyword%";
    1869         }
    1870     }
    1871    
    1872     $select = " select c_album.*";
    1873     $from = " FROM c_album";
    1874     $order = " ORDER BY r_datetime desc";
    1875    
    1876     $sql = $select . $from . $where . $order;
    1877     $list = db_get_all_limit($sql,($page-1)*$page_size,$page_size,$params);
    1878     foreach ($list as $key => $value) {
    1879         $list[$key]['c_member'] = db_member_c_member_with_profile($value['c_member_id']);
    1880         $list[$key]['count_comments'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    1881     }
    1882    
    1883     $sql =
    1884         "SELECT count(*) "
    1885         . $from
    1886         . $where ;
    1887     $total_num = db_get_one($sql,$params);
    1888    
    1889     $total_page_num =  ceil($total_num / $page_size);
    1890     $next = ($page < $total_page_num);
    1891     $prev = ($page > 1);
    1892    
    1893     return array($list , $prev , $next, $total_num,$total_page_num); 
    1894 }
    1895 
    1896 function monitor_album_comment_list($keyword,$page_size,$page)
    1897 {
    1898 
    1899     $page = intval($page);
    1900     $page_size = intval($page_size);
    1901    
    1902     $where = " where 1 ";
    1903 
    1904     if ($keyword) {
    1905         //全角空白を半角に統一
    1906         $keyword = str_replace(" ", " ", $keyword);
    1907         $keyword_list = explode(" ", $keyword);
    1908            
    1909         for($i=0;$i < count($keyword_list);$i++) {
    1910             $keyword = check_search_word( $keyword_list[$i] );
    1911                
    1912             $where .= " and (c_album_comment.body like ? ) ";
    1913             $params[]="%$keyword%";
    1914         }
    1915     }
    1916    
    1917     $select = " select c_album_comment.*,c_album.subject";
    1918     $from = " FROM c_album_comment"
    1919         ." LEFT JOIN c_album ON c_album.c_album_id = c_album_comment.c_album_id ";
    1920     $order = " ORDER BY r_datetime desc";
    1921    
    1922     $sql = $select . $from . $where . $order;
    1923     $list = db_get_all_limit($sql,($page-1)*$page_size,$page_size,$params);
    1924     foreach ($list as $key => $value) {
    1925         $list[$key]['c_member'] = db_member_c_member_with_profile($value['c_member_id']);
    1926         $list[$key]['count_comments'] = db_album_count_c_album_comment4c_album_id($value['c_album_id']);
    1927     }
    1928    
    1929     $sql =
    1930         "SELECT count(*) "
    1931         . $from
    1932         . $where ;
    1933     $total_num = db_get_one($sql,$params);
    1934    
    1935     $total_page_num =  ceil($total_num / $page_size);
    1936     $next = ($page < $total_page_num);
    1937     $prev = ($page > 1);
    1938    
    1939     return array($list , $prev , $next, $total_num,$total_page_num); 
    1940604}
    1941605
     
    1966630        }
    1967631    } else {
    1968        
    1969         //TODO c_tmp_image4filename()内容チェック
    1970632        $c_tmp_image = c_tmp_image4filename($tmpfile);
    1971633
     
    1976638            'type' => '',
    1977639        );
    1978         //kazuki インスタンス作成する必要あり?
    1979         //$db =& db_get_instance('image');
    1980640       
    1981641        if (db_insert("c_image_album", $params)) {
     
    1985645    return false;
    1986646}
    1987 
    1988 /*
    1989 function _do_insert_c_image_album($filename, $filepath)
    1990 {
    1991     return db_image_insert_c_image_album2($filename, $filepath);
    1992 }
    1993 */
    1994647
    1995648function db_image_insert_c_image_album2($filename, $filepath)
     
    2021674}
    2022675
     676//管理画面用に残しておく
    2023677function db_image_c_album_image_list($page, $page_size, &$pager)
    2024678{
     
    2042696}
    2043697
     698/*
    2044699function db_image_c_album_image4c_image_id($c_image_id)
    2045700{
     
    2050705    return $db->get_row($sql, $params);
    2051706}
    2052 
    2053 function album_image_data_delete($image_filename)
    2054 {
    2055     return db_album_image_data_delete($image_filename);
    2056 }
     707*/
    2057708
    2058709function db_album_image_data_delete($image_filename)
     
    2077728}
    2078729
    2079 function db_admin_delete_c_album_image_link4image_filename($image_filename)
    2080 {
    2081     // c_banner (削除)
    2082     $sql = 'DELETE FROM c_banner WHERE image_filename = ?';
    2083     $params = array($image_filename);
    2084     db_query($sql, $params);
    2085 
    2086     $tbl = 'c_album_image';
    2087     _db_admin_empty_image_filename($tbl, $image_filename);
    2088    
    2089 
    2090     // c_diary_comment
    2091     $tbl = 'c_album_comment';
    2092     _db_admin_empty_image_filename($tbl, $image_filename, 'image_filename_1');
    2093     _db_admin_empty_image_filename($tbl, $image_filename, 'image_filename_2');
    2094     _db_admin_empty_image_filename($tbl, $image_filename, 'image_filename_3');
    2095 
    2096 }
    2097 
    2098730function db_image_is_c_album_image4filename($filename)
    2099731{
     
    2107739}
    2108740
     741/*
    2109742function admin_insert_c_image_album($upfile_obj, $filename)
    2110743{
     
    2118751    return false;
    2119752}
    2120 
    2121 //get open_album_list for login page
    2122 function db_album_get_album_list()
    2123 {
    2124     $sql = "SELECT c_album_id,subject,album_cover_image FROM c_album WHERE public_flag = 'public' order by r_datetime desc";
    2125     $params = array();
    2126     return db_get_all($sql,$params);
    2127 }
    2128 
    2129 /**get community list to be selected in h_album_add
    2130  *
    2131  * @author Napster
    2132  * @param string $sql
    2133  * @param array $params
    2134  * @return array contains c_commu_id & name
    2135  *
    2136  */
    2137 function db_album_get_commu_list4c_member_id($c_member_id)
    2138 {
    2139     $sql = "SELECT c_commu.c_commu_id,c_commu.name " .
    2140            "FROM c_commu,c_commu_member " .
    2141            "WHERE c_commu_member.c_member_id = ? AND c_commu_member.c_commu_id = c_commu.c_commu_id";
    2142     $params = array(intval($c_member_id));
    2143     return db_get_all($sql,$params);
    2144 }
    2145 
    2146 function db_get_commu_name4c_commu_id($taget_c_commu_id)
    2147 {
    2148     $sql = "SELECT name FROM c_commu WHERE c_commu_id = ?";
    2149     $params = array(intval($taget_c_commu_id));
    2150     return db_get_one($sql,$params);
    2151 }
    2152 
    2153 function db_o_album_category_list()
    2154 {
    2155     $sql = "SELECT c.c_album_id,c.album_cover_image,ch.nickname,ch.c_member_id FROM c_album c,c_member ch WHERE ch.c_member_id =c.c_member_id and public_flag = 'public' order by r_datetime desc limit 4";
    2156 
    2157     return db_get_all($sql);
    2158 }
    2159 function db_o_album_content_list($c_ablum_id)
    2160 {
    2161     $sql = "SELECT image_filename,c_album_image_id FROM c_album_image WHERE c_album_id = ? limit 3";
    2162     $params = array(intval($c_ablum_id));
    2163     return db_get_all($sql,$params);
    2164 }
    2165 
    2166 function db_o_album_point($c_ablum_id)
    2167 {
    2168     $sql = "SELECT point FROM c_album WHERE c_album_id = ? ";
    2169     $params = array(intval($c_ablum_id));
    2170     return db_get_one($sql,$params);
    2171 }
    2172 
    2173 function db_album_insert_c_album_point($c_member_id,$target_c_album_id)
    2174 {
    2175     $data = array(
    2176    
    2177         'c_member_id' => $c_member_id,
    2178         'c_album_id' => $target_c_album_id,
    2179          'release_date' => db_now(),
    2180     );
    2181 
    2182    
    2183 
    2184     return db_insert('c_album_rank_pre', $data);
    2185 }
    2186 
    2187 function db_o_album_point_list()
    2188 {
    2189     $sql = "SELECT ch.c_member_id,c.subject,c.c_album_id,c.album_cover_image,c.r_datetime,ch.nickname,count(chc.c_album_rank_pre_id) as point_num " .
    2190             "FROM c_album c,c_member ch,c_album_rank_pre chc " .
    2191             "WHERE c.c_member_id=ch.c_member_id and c.c_album_id=chc.c_album_id " .
    2192             "group by chc.c_album_id " .
    2193             "order by point_num desc limit 5";
    2194 
    2195     return db_get_all($sql);
    2196 }
    2197 
    2198 /**
    2199  * アルバムの情報を更新
    2200  */
    2201 function db_album_update_c_album_cover($c_album_id,$subject,$description,$album_cover_image,$public_flag)
    2202 {
    2203     $data = array(
    2204         'subject' => $subject,
    2205         'description' => $description,
    2206         'public_flag' => $public_flag,
    2207     );
    2208     if ($album_cover_image) $data['album_cover_image'] = $album_cover_image;
    2209 
    2210     $where = array(
    2211         'c_album_id' => intval($c_album_id),
    2212     );
    2213 
    2214     return db_update('c_album', $data, $where);
    2215 }
     753*/
    2216754
    2217755?>
Note: See TracChangeset for help on using the changeset viewer.