<div>
    <?php
    $user_id = $this->session->userdata('user_id');
    $offset = $this->session->userdata('time_offset');
    $nested_comment_counter = 0;
    $you_tube_regExp = '/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/';
    $vimo_regExp = '/(?:vimeo)\.com.*(?:videos|video|channels|)\/([\d]+)/i';
    foreach ($nested_reply as $nested_reply_value) {
        ?>
        <hr>
        <div class="media-left">
            <a href="<?php echo base_url() . $nested_reply_value->url . '/profile'; ?>">
                <img class="media-object post_comment_image" 
                     src="<?php
                     if ($nested_reply_value->person_image) {
                         echo base_url() . 'content-library/' . $nested_reply_value->url . '/' . $nested_reply_value->person_image;
                     } else {
                         echo base_url() . 'image/no_profile_picture.png';
                     }
                     ?>" 
                     alt="<?php echo $nested_reply_value->person_first_name . ' ' . $nested_reply_value->person_last_name; ?>">
            </a>
        </div>
        <div class="media-body">
            <h5 class="media-heading green text-justify" style="font-size: 16px;text-align: left !important">
                <a href="<?php echo base_url() . $nested_reply_value->url . '/profile'; ?>">
                    <?php 
                    if(strlen($nested_reply_value->person_first_name) && strlen($nested_reply_value->person_last_name) < 20){
                        echo $nested_reply_value->person_first_name . ' ' . $nested_reply_value->person_last_name; 
                        }
                    else{
                            echo substr($nested_reply_value->person_first_name, 0, 30).' '.substr($nested_reply_value->person_last_name, 0, 20);
                        }
                    //echo $nested_reply_value->person_first_name . ' ' . $nested_reply_value->person_last_name; 
                    ?>
                </a>
            </h5>
            <p class="text-justify" id="reply_comment_detail<?php echo $nested_reply_value->comment_id; ?>">
                <?php
                $function_name = 'viewDetails(&quot;' . base_url('post/view_post_details/' . $nested_reply_value->comment_id . '/reply') . '&quot;,&quot;reply_comment_detail&quot;,&quot;' . $nested_reply_value->comment_id . '&quot;)';
                echo $this->tt_post->get_post_data($nested_reply_value->comment_details, 80, $function_name);
                ?>
            </p>
        </div>


        <!-----------------Start View URL Details (if user Comment Reply URL)------------------------>
        <?php
        if ($nested_reply_url[$nested_reply_value->comment_id]) {
            $url_value = explode("URL: ", $nested_reply_url[$nested_reply_value->comment_id]->post_comment_url_info);

            if (preg_match($you_tube_regExp, $url_value[1])) {
                ?>
                <div class="col-sm-12 text-left" style="margin: -10px 0 0 40px; ">
                    <div class="col-sm-4 col-xs-12 text-left">
                        <div class="embed-responsive embed-responsive-16by9" >
                            <iframe class="embed-responsive-item"   width="200" height="150"  webkitallowfullscreen mozallowfullscreen allowfullscreen
                                    src="<?php echo $url_value[1]; ?>">
                            </iframe>
                        </div>
                    </div>
                </div>
                <?php
            } else if (preg_match($vimo_regExp, $url_value[1])) {
                ?>
                <div class="col-sm-12 text-left" style="margin: -10px 0 0 40px; ">
                    <div class="col-sm-4 col-xs-12 text-left">
                        <div class="embed-responsive embed-responsive-16by9" >
                            <iframe class="embed-responsive-item"   src="<?php echo $url_value[1]; ?>" 
                                    width="200" height="150" 
                                    frameborder="0" 
                                    webkitallowfullscreen mozallowfullscreen allowfullscreen>
                            </iframe>
                        </div>
                    </div>
                </div>
                <?php
            } else {
                ?>
                <div class="col-sm-12 text-left" style="margin: -10px 0 0 40px; ">
                    <div class="col-sm-12">
                        <h5>
                            <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                <?php echo $url_value[2]; ?>
                            </a>
                        </h5>
                    </div>
                    <div class="col-sm-12" style="margin-top: -10px;">
                        <p style="font-size: 12px; text-align: justify;">
                            <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                <?php echo $url_value[3]; ?>
                            </a>
                        </p>
                    </div>
                    <div class="col-sm-12" style="margin-top: -10px;">
                        <h6>
                            <?php
                            if ($url_value[1]) {
                                ?>
                                <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457">
                                    <?php echo $url_value[1]; ?>
                                </a>
                                <?php
                            }
                            if ($url_value[4] == '') {
                                echo '';
                            } else {
                                echo 'BY | ';
                                ?>
                                <a href="<?php echo $url_value[1]; ?>" target="_blank" style="color: #545457"><?php echo $url_value[4]; ?></a>
                                <?php
                            }
                            ?>
                        </h6>
                    </div>
                </div>
                <?php
            }
        }
        ?>
        <!-----------------END View URL Details (if user Comment Reply URL)------------------------>

        <div id="nested_reply_like<?php echo $nested_reply_value->comment_id ?>" class="padding-zero">
            <div class="media-bottom" style="margin-left: 55px" >
                <p class="text-justify">   
                    <?php
                    $post_comment_reply_like_array = explode(",", $nested_reply_value->comment_like_by);
                    if (in_array($user_id, $post_comment_reply_like_array)) {
                        ?>
                        <a href="javascript:void(0)" style="color:red"
                           onclick="getNestedReplyLikeValue('<?php echo base_url() . 'post/add_replies_like/' . $nested_reply_value->comment_id . '/' . $user_id . '/' . 'dislike'; ?>', '<?php echo $nested_reply_value->comment_id; ?>')" >
                            <img src="<?php echo base_url() ?>image/home/red_like_icon.png" width="15" height="20" style="margin-top: -7px;" title="Unread">
                        </a> -
                    <?php } else { ?>
                        <a href="javascript:void(0)"
                           onclick="getNestedReplyLikeValue('<?php echo base_url() . 'post/add_replies_like/' . $nested_reply_value->comment_id . '/' . $user_id . '/' . 'like'; ?>', '<?php echo $nested_reply_value->comment_id; ?>')" >
                            <img src="<?php echo base_url() ?>image/home/like-icon.png" width="15" height="20" style="margin-top: -7px;" title="Read">
                        </a> -
                    <?php }
                    ?>

                    <a href="javascript:void(0)"
                       onclick="addNestedReplyForm('<?php echo base_url() . 'post/add_comment_nested_reply_form/' . $nested_reply_value->comment_id . '/' . $user_id; ?>', '<?php echo $nested_reply_value->comment_id; ?>')" >
                        <i class="fa fa-share" style=" -ms-transform: rotate(90deg); -webkit-transform: rotate(90deg); transform: rotate(90deg);" aria-hidden="true" title="Reply"></i>
                    </a> 

                    <?php
                    if ($post_value->posted_by == $user_id || $parent_comment_value->comment_reply_by == $user_id || $comment_value->comment_reply_by == $user_id || $nested_reply_value->comment_reply_by == $user_id) {
                        ?>
                        - <a href="javascript:void(0)"
                             onclick="deleteComment('<?php echo base_url() . 'post/delete_nested_reply' ?>', '<?php echo $nested_reply_value->comment_id; ?>', '<?php echo $comment_value->comment_id ?>', 'nested')" >
                            <i class="fa fa-trash"  aria-hidden="true" title="Delete"></i>
                        </a> 
                    <?php } ?>

                    - <span>
                        <?php
                        $this->utility_model->time_format_for_read_write($nested_reply_value->comment_date_time);
                        ?>
                    </span> 
                </p>
            </div>
            <div class="text-left" style="margin-left: 55px">
                <?php
                if ($nested_reply_value->comment_like_by != '') {
                    $nested_like_value = $nested_reply_value->comment_like_by;
                    $this->cf->read_write_status($user_id, $nested_reply_value->comment_like_by, 'nested' . $nested_reply_value->comment_id);
                    $nested_like_id_array = explode(',', $nested_like_value);
                    ?>
                    <div id="viewLikeModal_nested<?php echo $nested_reply_value->comment_id ?>" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                        <div class="modal-dialog modal-md">
                            <div class="modal-content white_ttc" >

                                <div class="modal-header  text-left" style="padding: 20px 20px 0 20px;">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" style=" opacity: 1"><span aria-hidden="true"><strong  style="color: #80c12c;">&times;</strong></span></button>
                                    <span class="modal-title" id="gridSystemModalLabel">
                                        <img class="pull-left" style="width: 30px" src="<?php echo base_url() ?>image/home/like-icon.png">
                                        <div class="form-group"></div> <strong><?php echo '&nbsp;&nbsp;&nbsp;' . count($nested_like_id_array); ?></strong>
                                    </span>
                                </div>
                                <div class="modal-body padding-top-zero">
                                    <div class="row">
                                        <div class="col-sm-12 padding-zero"  style="border-top: 2px solid #80c12c;height: 320px;overflow-y: scroll">
                                            <div class="col-sm-12 form-group"></div>
                                            <div class="col-sm-12">
                                                <?php
                                                foreach ($nested_reply_liked_person[$nested_reply_value->comment_id] as $nested_reply_person_value) {
                                                    ?>
                                                    <div class="media">
                                                        <div class="media-left">
                                                            <?php if ($nested_reply_person_value->person_image != '') {
                                                                ?>
                                                                <img class="media-object" src="<?php echo base_url() . 'content-library/' . $nested_reply_person_value->url . '/' . $nested_reply_person_value->person_image; ?>" 
                                                                     alt="<?php echo $nested_reply_person_value->person_first_name . ' ' . $nested_reply_person_value->person_last_name ?>" style="width: 50px;height: 50px">
                                                                     <?php
                                                                 } else {
                                                                     ?>
                                                                <img class="media-object" src="<?php echo base_url() . 'image/no_profile_picture.png'; ?>" 
                                                                     alt="<?php echo $nested_reply_person_value->person_first_name . ' ' . $nested_reply_person_value->person_last_name ?>" style="width: 50px;height: 50px">
                                                                     <?php
                                                                 }
                                                                 ?>
                                                        </div>
                                                        <div class="media-body">
                                                            <h2 class="media-heading" style="margin-top: 15px">
                                                                <a href="<?php echo $nested_reply_person_value->url ?>" target="_blank">
                                                                    <?php echo $nested_reply_person_value->person_first_name . ' ' . $nested_reply_person_value->person_last_name ?>
                                                                </a>
                                                                <?php
                                                                if ($nested_reply_person_value->person_id != $user_id) {
                                                                    if (!in_array($nested_reply_person_value->person_id, $all_link)) {
                                                                        ?>
                                                                        <span style="color: #80c12c" class="pull-right" title="Add to your link"> 
                                                                            <sub style="font-weight: bold"> + </sub> <i class="fa fa-link"></i>
                                                                        </span>
                                                                        <?php
                                                                    }
                                                                }
                                                                ?>
                                                            </h2>
                                                        </div>
                                                        <hr>
                                                    </div>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div> 
                                    </div>
                                </div>
                            </div><!-- /.modal-content -->
                        </div>
                    </div>
                    <?php
                } else {
                    $this->cf->read_write_status($user_id, '', '');
                }
                ?>
            </div>
            <!------------------------------------ Start Nested Reply Form----------------------------- -->
            <div class="col-sm-12" style="margin-left: -30px; display: none"
                 id="add_nested_reply_form<?php echo $nested_reply_value->comment_id; ?>" >
            </div>
            <!------------------------------------END Nested Reply Form----------------------------- -->
        </div>
        <div style="display: none"
             id="view_saaved_nested_replies<?php echo $nested_reply_value->comment_id; ?>" >
        </div>


        <?php
        $replies_reply_counter = 0;
        if ($total_replies_reply[$nested_reply_value->comment_id]->total_comment > 0 && $total_replies_reply[$nested_reply_value->comment_id]->total_comment != $replies_reply_counter) {
            ?>
            <div id="view_nested_replies<?php echo $nested_reply_value->comment_id; ?>">
                <div class="col-sm-12 text-left" style="margin-left: 40px;">
                    <a href="javascript:void(0)"
                       onclick="viewNestedReplies('<?php echo base_url() . 'post/view_nested_replies/' . $nested_reply_value->comment_id . '/' . $replies_reply_counter; ?>', '<?php echo $nested_reply_value->comment_id; ?>')" >
                        view replies
                    </a>
                </div>
            </div>
        <?php } ?>

        <!--</div>-->
        <?php
        $nested_comment_counter++;
    }
    ?>
    <div class="col-sm-12 text-left" id="view_nested_replies<?php echo $comment_value->comment_id; ?>">
        <?php
        if ($total_nested_reply->total_comment > 0 && $total_nested_reply->total_comment != $nested_comment_counter) {
            ?>
            <div class="col-sm-12 text-left" style="margin-left: 40px;">
                <a href="javascript:void(0)"
                   onclick="viewNestedReplies('<?php echo base_url() . 'post/view_nested_replies/' . $comment_value->comment_id . '/' . $nested_comment_counter; ?>', '<?php echo $comment_value->comment_id; ?>')" >
                    view replies
                </a>
            </div>
        <?php } ?>
    </div>
</div>