Changeset 20315 for events

Show
Ignore:
Timestamp:
09/30/08 22:16:35 (2 months ago)
Author:
kenji
Message:

Update Ajax post

Location:
events/phpframework/codeigniter/trunk/system/application
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/codeigniter/trunk/system/application/controllers/status.php

    r19980 r20315  
    1616        function update() 
    1717        { 
     18                $this->session->keep_flashdata('ticket'); 
     19                header('Content-Type: application/json; charset=UTF-8'); 
     20 
    1821                // CSRF チェック 
    1922                $ticket = $this->session->flashdata('ticket'); 
     
    2326                { 
    2427                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted Comment but Wrong Ticket'); 
     28                        echo json_encode(array('status' => 'ng', 'html' => 'チケットが異なります')); 
    2529                        exit; 
    2630                } 
    27  
    28                 $this->session->keep_flashdata('ticket'); 
    2931 
    3032                $comment = $this->input->post('msg'); 
     
    3638                { 
    3739                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted Comment but strlen = ' . $len); 
     40                        echo json_encode(array('status' => 'ng', 'html' => '文字数が不正です: ' . $len)); 
    3841                        exit; 
    3942                } 
     
    5558                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted Page: ' . $page); 
    5659 
    57                         $id = $this->Status_model->add_comment($user_id, $reply_username, $comment); 
     60                        list($id, $reply_username) = $this->Status_model->add_comment($user_id, $reply_username, $comment); 
    5861 
     62                        $this->load->helper(array('url')); 
     63                         
    5964                        $data->page     = $page; 
    6065                        $data->username = $this->session->userdata('username'); 
    6166                        $data->image    = $this->session->userdata('image'); 
    62                         $data->comment  = htmlspecialchars($comment, ENT_QUOTES); 
     67                         
     68                        $comment = h($comment); 
     69                        if ($reply_username) { 
     70                                $comment = preg_replace('/^@(\w+)\s/', '@' . anchor(site_url('user/index/' . $reply_username), $reply_username) . ' ', $comment); 
     71                        } 
     72                         
     73                        $data->comment  = $comment; 
    6374                        $data->user_id  = $user_id; 
    6475                        $data->id       = $id; 
    6576 
    66                         $this->load->helper(array('url')); 
    6777                        $data->created_at = time(); 
    6878 
    69                         $this->load->view('status/comment', $data); 
     79                        $html = $this->load->view('status/comment', $data, TRUE); 
     80 
     81                        echo json_encode(array('status' => 'ok', 'html' => $html)); 
    7082                } 
    7183                else 
    7284                { 
     85                        echo json_encode(array('status' => 'ng', 'html' => 'ログインしていません')); 
    7386                        log_message('info', '[class]' . __CLASS__ . '/' . __FUNCTION__ . '(): Posted Comment but Not Logged in'); 
    7487                } 
  • events/phpframework/codeigniter/trunk/system/application/models/status_model.php

    r20309 r20315  
    1515                { 
    1616                        $statuses->reply_user_id = $this->get_userid($reply_username); 
     17                        if ( ! $statuses->reply_user_id ) 
     18                        { 
     19                                $reply_username = ''; 
     20                        } 
    1721                } 
    1822                else 
     
    2630                $id = $this->db->insert_id(); 
    2731 
    28                 return $id; 
     32                return array($id, $reply_username); 
    2933        } 
    3034 
  • events/phpframework/codeigniter/trunk/system/application/views/js/default.php

    r20311 r20315  
    44                comment = $('#message').val(); 
    55                $.post('<?=site_url('status/update')?>', {msg: comment,  
    6                                 ticket: $('#ticket').val(), p: $('#page_').val()}, addComment, 'html'); 
     6                                ticket: $('#ticket').val(), p: $('#page_').val()}, addComment, 'json'); 
    77                $('#message').val('').focus(); 
     8        }); 
     9}); 
     10function addComment(data){ 
     11        if (data.status == 'ok') { 
     12                $('tbody:first').prepend(data.html); 
    813                $('p#last_comment').text(comment); 
    914                count = parseInt($('#side_count_post').text()) + 1; 
    1015                $('#side_count_post').text(count); 
    11         }); 
    12 }); 
    13 function addComment(data){ 
    14         $('tbody:first').prepend(data);          
     16        } 
     17        else { 
     18                alert(data.html); 
     19        } 
    1520} 
    1621 
  • events/phpframework/codeigniter/trunk/system/application/views/status/comment.php

    r20198 r20315  
    88                                <?=anchor(site_url('user/index/' . $username), $username)?> 
    99                                <?php endif ?> 
    10                                 <?=h($comment)?> 
     10                                <?=$comment?> 
    1111                                <?=anchor(site_url('user/statuses/' . $username . '/' . $id), posted_time($created_at))?> 
    1212                                </p>