<?php echo $this->Html->script(array('site_js/common')); ?>
<style>
    .cmlikespid {

        cursor: pointer;

    }

    #loadMore {
        cursor: pointer;
        margin-bottom: 10px;
        margin-left: 70px;
    }
.cbox{
    border-radius: 5px;
}
</style>


<script>
    $(document).ready(function () {
        $(".buttonc").click(function () {
            $(".cancel").hide(1000);
        });
    });
</script>


<div class="col-sm-12 pl0 pr0">
    <?php
    $ww_root = $this->webroot;
    $total_like = '';
    if ($position) {
        $i = $position + 1;
    } else {
        $i = 1;
    }

    foreach($walllist as $wall):
    $total_likes = ClassRegistry::init('Profileslatelike')->find('all', array('conditions' => array('Profileslatelike.profileslate_id' => $wall['Profileslate']['id']), 'recursive' => -1));
    $total_like = sizeof($total_likes);
    if (empty($total_likes)):
        $lun = 'Like';
        $fun_n = 'like_by_wall_id';
    else :
        foreach ($total_likes as $like):
            if ($like['Profileslatelike']['user_id'] == $loggedUser['id']):
                $lun = 'Liked';
                $fun_n = 'unlike_by_wall_id';
                break;
            else:
                $lun = 'Like';
                $fun_n = 'like_by_wall_id';
            endif;
        endforeach;
    endif;

    if (!empty($wall['Profileslate']['postedId'])):
        $profile_id = $wall['Profile']['id'];
        $name = $wall['Profile']['fname'] . ' ' . $wall['Profile']['lname'];
        $photo = $wall['Profile']['link1'];
    else:
        $profile_id = $wall['Prof']['id'];
        $name = $wall['Prof']['fname'] . ' ' . $wall['Prof']['lname'];
        $photo = $wall['Prof']['link1'];
    endif;

    if ($wall['Profileslate']['user_id'] == $loggedUser['id'] || $wall['Profileslate']['postedId'] == $loggedUser['id']):
        //$delete = "<i class='fa fa-times'></i>";


        $del = $this->Form->postLink(__("<i class='fa fa-times'></i>"), array('action' => 'delete', $wall['Profileslate']['id'], $wall['Prof']['id'], $wall['Profileslate']['user_id']), array('escape' => false), __('Are you sure you want to delete this post?'));


    else:
        $del = '';
    endif;
    ?>
    <div class="row-fluid <?php echo 'wall' . $i;?>">
        <div class="shdw brd pd5 mrb10 cbox">
            <div class="row-fluid">
                <div class="">
                    <div style="max-height: 50px; max-width: 50px; width: 7%; float: left;">
                        <?php
                        if (!empty($photo)){?>
                        <img src="<?php echo $photo;?>" width="50px" height="50px" min-width="50px;" style=" margin: 5px 0px 0px 14px; border-radius: 50%;">
                        <?php }else {?> 
                            <img src="<?php echo $this->webroot?>img/profile.jpg" height="50px" width="50px" style=" margin: 5px 0px 0px 14px; border-radius: 50%;">
                       <?php } ?>
                    </div>
                     <span class="topright"><?php echo $del;?></span>
                    <div class="w97p fnt80">
                        <span class="profile-name mainName">
                        <?php
                            if (!empty($name)) {
                                echo $this->Html->link($name, array('controller' => 'profiles', 'action' => 'about', base64_encode($profile_id), rand(1111, 9999) . $profile_id));
                            } else {
                                echo 'Annoymous';
                            }

                            ?>
                        </span>  
                         <span class="fl cash" style="position: absolute;margin: 24px 20px">
                            <?php 
                               $adte = $wall['Profileslate']['created'];
                               $localtime = timeAgo($wall['Profileslate']['created']); 
                               if ($localtime == 'true') {
                                   echo getTimeZoneConvert($adte, $timezone);
                               } else {
                                   echo timeAgo($adte);
                               }  
                            ?>
                        </span>
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="prelative" style="width: 100%; padding: 17px 17px;  line-height: 1.4;"> 
                    <div class="w100p" style="text-align: justify;">
                          <?php
                        if (strlen($wall['Profileslate']['content']) > 1020) {
                            $reading = $this->Html->link('...Continue reading', array('controller' => 'profileslates', 'action' => 'view', base64_encode($wall['Profileslate']['id'])), array('style' => 'color:#5050df'));
                            echo substr($wall['Profileslate']['content'], 0, 1020) . $reading;
                        } else {
                            echo $wall['Profileslate']['content'];
                        }
                        ?>
                    </div>
                    <?php
                    switch ($wall['Profileslate']['type']){
                    case 1:
                        if (!empty($wall['Profileslate']['linkfile'])) {
                            echo
                                '<div class="ih150 pdt5 mrt5">' .
                                "<a href=" . $wall['Profileslate']['linkfile'] . " download=" . $wall['Profileslate']['linkfile'] . " class='cblue fnt80' target='_blank'>" . $wall['Profileslate']['filename'] . "</a>" .
                                '</div>';
                        }
                        break;
                    case 2:
                        if (!empty($wall['Profileslate']['link1'])) {
                            echo '<div class="ih150 pdt5 mrt5 tac" >' . "<a href=" . $wall['Profileslate']['link2'] . " data-lightbox='example-set' class='cblue fnt80 example-image-link'>" . "<img  src=" . $wall['Profileslate']['link1'] . ">" . "</a>" . '</div>';
                        }
                        break;
                    case 3:
                        if (!empty($wall['Profileslate']['link1'])) {
                            $wall_meta = '';
                            if (!empty($wall['Profileslate']['meta'])) {
                                $wall_meta = $wall['Profileslate']['meta'] . '<br/>';
                            }
                            if (strlen($wall['Profileslate']['lnk']) > 100) {
                                $sitelink = $this->Html->link(substr($wall['Profileslate']['lnk'], 0, 100) . '....', $wall['Profileslate']['lnk'], array('target' => '_blank', 'class' => 'cblue'));
                            } else {
                                $sitelink = $this->Html->link($wall['Profileslate']['lnk'], $wall['Profileslate']['lnk'], array('target' => '_blank', 'class' => 'cblue'));
                            }
                            echo '<div class="ih150 pdt5 mrt5">
                                <div class="row-fluid">
                                    <div class="fnt80" style="float:left; margin-top: 5px;margin-right: 10px;min-height: 70px;">' . "<a href=" . $wall['Profileslate']['link1'] . " download=" . $wall['Profileslate']['link1'] . " class='cblue fnt80' target='_blank'>" . "<img  src=" . $wall['Profileslate']['link1'] . ">" . "</a>" . '</div>
                                    <div class="fnt80">' . $wall_meta . $sitelink . '</div>
                                </div>
                            </div>';
                        } elseif (!empty($wall['Profileslate']['meta'])) {
                            if (strlen($wall['Profileslate']['lnk']) > 100) {
                                $sitelink = $this->Html->link(substr($wall['Profileslate']['lnk'], 0, 100) . '....', $wall['Profileslate']['lnk'], array('target' => '_blank', 'class' => 'cblue'));
                            } else {
                                $sitelink = $this->Html->link($wall['Profileslate']['lnk'], $wall['Profileslate']['lnk'], array('target' => '_blank', 'class' => 'cblue'));
                            }
                            echo
                                '<div class="ih150 pdt5 mrt5">
                                                                        <div class="fnt80">' . $wall['Profileslate']['meta'] . '</div>
                                                                        <div class="fnt80">' . $sitelink . '</div>
                                                                </div>';
                        } else {
                            if (strlen($wall['Profileslate']['lnk']) > 100) {
                                $sitelink = $this->Html->link(substr($wall['Profileslate']['lnk'], 0, 100) . '....', $wall['Profileslate']['lnk'], array('target' => '_blank', 'class' => 'cblue'));
                            } else {
                                $sitelink = $this->Html->link($wall['Profileslate']['lnk'], $wall['Profileslate']['lnk'], array('target' => '_blank', 'class' => 'cblue'));
                            }
                            echo
                                '<div class="ih150 pdt5 mrt5 fnt80">
                                                                        <div>' . $sitelink . '</div>
                                                                </div>';
                        }
                        break;
                    case 4:
                    if(!empty($wall['Profileslate']['lnk'])){
                    ?>
                    <div class=" ih150 pdt5 mrt5">
                        <?php
                        $vdImg = explode("watch?v=", $wall['Profileslate']['lnk']);
                        ?>
                        <div id="Ytvd_<?php echo $wall['Profileslate']['id'];?>"></div>
                        <div class="row-fluid">
                            <?php if (!empty($wall['Profileslate']['link1'])){?>
                            <div id="vdoImg_<?php echo $wall['Profileslate']['id'];?>" class=""
                                 style="width:18%; float: left;">
                                <a href="javascript:;" class="fileLink prelative"
                                   onclick="_vd('<?php echo $vdImg[1];?>','<?php echo $wall['Profileslate']['id'];?>')">
                                    <i class="fa fa-play fa-2x pmiddle"></i>
                                    <img src="<?php echo $wall['Profileslate']['link1']; ?>"/>
                                </a>
                            </div>
                            <?php }?>
                            <div class="fnt80" style="width: 93%;">
                                <div><?php echo $wall['Profileslate']['meta'];?></div>
                                <div><?php
                                    if (strlen($wall['Profileslate']['lnk']) > 60) {
                                        echo $this->Html->link(substr($wall['Profileslate']['lnk'], 0, 60) . '....', $wall['Profileslate']['lnk'], array('target' => '_blank', 'escape' => false, 'class' => 'cblue'));
                                    } else {
                                        echo $this->Html->link($wall['Profileslate']['lnk'], $wall['Profileslate']['lnk'], array('target' => '_blank', 'escape' => false, 'class' => 'cblue'));
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php
                    }
                    break;

                    }
                    ?>
                <!-- like-comment -->

                    <?php

                    $totalComment = ClassRegistry::init('Profileslatecomment')->find('count', array('conditions' => array('Profileslatecomment.profileslate_id' => $wall['Profileslate']['id']), 'recursive' => -1));

                    ?>
                    <div class="tar fnt80 pdt5 mrt5"> 
                        <span onclick="<?php echo $fun_n ?> &nbsp;( '<?php echo $ww_root?>profileslatelikes','<?php echo $wall['Profileslate']['id'] ?>',<?php echo $total_like;?> );"
                            id="<?php echo 'lun' . $wall['Profileslate']['id'] ?>"
                            style="cursor: pointer; margin-right:5px;"><?php echo $lun . '(' . $total_like . ')'?>
                        </span> 

                        <span id="btnComment<?php echo $i;?>" class="btnComment<?php echo $i;?>"
                              onclick="addFrm(<?php echo $i;?>,<?php echo $wall['Profileslate']['id']?>);"
                              style="cursor: pointer;"> Comment(<span
                                id="btnCommentcnt<?php echo $i;?>"><?php echo $totalComment;?></span>)</span>

                    </div>
                </div>
            </div>
        </div>

        <div id="commentForm<?php echo $i;?>" class="walls form userForm single-wall-display ml67 cancel"
             style="display: none;">
        </div>
        <ul class="myList<?php echo $i; ?>">
            <div id="newcomment<?php echo $i;?>"></div>
            <?php
            $arr_comments = ClassRegistry::init('Profileslatecomment')->find('all', array('conditions' => array('Profileslatecomment.profileslate_id' => $wall['Profileslate']['id']), 'recursive' => -1, 'limit' => 3, 'order' => 'Profileslatecomment.id DESC'));
            if(sizeof($arr_comments) > 0):
            $wallcommentLike = ClassRegistry::init('Profileslatecommentlike');
            $conut = '';
            foreach ($arr_comments as $comment):
            /* echo '<pre>';
         print_r($comment);
         echo '<pre>';*/
            //pr($arr_comments);die();
            if ($wallcommentLike->checkme($comment['Profileslatecomment']['id'], $loggedUser['id'])) {
                $lun = 'Liked';
                $fun_n = 'unlike_by_wall_id2';
            } else {
                $lun = 'Like';
                $fun_n = 'like_by_wall_id2';
            }
            if ($comment['Profileslatecomment']['user_id'] == $loggedUser['id'] || $wall['Profileslate']['user_id'] == $loggedUser['id']):
                $del = "<i class='fa fa-times'></i>";
            else:
                $del = '';
            endif;
            // pr($profileInfo2);
            ?>

            <script>

                var path = '<?php echo $this->webroot?>';
                var num = <?php echo $i; ?>;
                var ntota = 1;
                var $<?php echo $i; ?>ntota = 1;


                function getMoreComment<?php echo $i; ?>(vals) {

                    var totalcomments = <?php echo $totalComment; ?>;

                    loading_more = true;
                    $('.animation_image').show();

                    $.post(path + "profileslatecomments/getmorecoments", {
                        'group_no_more': $<?php echo $i; ?>ntota,
                        'psl': vals,
                        'totalcomments': totalcomments,
                        'timezone': timezone
                    }, function (data) {

                        var res = data.split("~~~");


                        if (totalcomments <= res[0]) {
                            $("#morereno" + vals).hide();
                        }

                        $("#moreresults" + vals).append(res[1]); //append received data into the element
                        //hide loading image
                        $('.animation_image').hide(); //hide loading image once data is received
                        loading_more = false;
                    }).fail(function (xhr, ajaxOptions, thrownError) { //any errors?
                        //alert(thrownError); //alert with HTTP error
                        $('.animation_image').hide(); //hide loading image
                        loading_more = false;
                    });
                    $<?php echo $i; ?>ntota++;
                }

            </script>

            <li class="row-fluid cbox" id="data_<?php echo $comment['Profileslatecomment']['id'];?>">
                <div class="span11 offset1">
                    <div class="shdw br5 brd pd5 mrb5">
                        <div class="row-fluid">
                            <div class="" style="max-height: 50px; max-width: 50px; width: 7%; float: left;">
                                <?php if ($comment['Profileslatecomment']['parent_id'] == 0){?>
                                <?php if (!empty($profileInfolink[$comment['Profileslatecomment']['user_id']])){?>
                                <img src="<?php echo $profileInfolink[$comment['Profileslatecomment']['user_id']];?>" style="border-radius: 50%" width="50px" height="50px">
                                <?php }else {?>
                                   <img src="<?php echo $this->webroot;?>img/profile.jpg" width="50px" height="50px" style="border-radius: 50%"> 
                                <?php }}elseif(!empty($photo)){?>
                                <img src="<?php echo $photo;?>" width="50px" height="50px" style="border-radius: 50%">
                                <?php }else {?> 
                                    <img src="<?php echo $this->webroot;?>img/profile.jpg" width="50px" height="50px" style="border-radius: 50%">
                               <?php }?>
                            </div>
                            <div class=" prelative" style="width: 93%; float: right; padding-left: 1%;">
                                <span class="topright">
                                    <a onclick="ddp('<?php echo $ww_root?>profileslatecomments','delete','<?php echo $comment['Profileslatecomment']['id']; ?>','<?php echo $i; ?>');"><?php echo $del;?></a>
                                </span>
                                <div class="w97p fnt80">
                                    <span class="profile-name" style="float: left;width: 100%">
                                    <?php
                                        if (!empty($profileInfo[$comment['Profileslatecomment']['user_id']])) {
                                            echo $profileInfo[$comment['Profileslatecomment']['user_id']];
                                        } else {
                                            echo 'Annoymous';
                                        }
                                    ?>
                                    </span>
                                     <span class="fl fnt80 cash" style="width: 100%">
                                                                                <?php


                                    $adte = $comment['Profileslatecomment']['created'];
                                    $localtime = timeAgo($comment['Profileslatecomment']['created']);
                                    if ($localtime == 'true') {
                                        echo getTimeZoneConvert($adte, $timezone);
                                    } else {
                                        echo timeAgo($adte);
                                    }
                                    ?>  </span>
                                </div>
                                  <div class="w100p fnt80">
                                    <?php
                                    if (strlen($comment['Profileslatecomment']['comment']) > 260) {
                                        $reading = $this->Html->link('...Continue reading', array('controller' => 'profileslatecomments', 'action' => 'view', $comment['Profileslatecomment']['id']), array('style' => 'color:#5050df'));
                                        echo substr($comment['Profileslatecomment']['comment'], 0, 260) . $reading;
                                    } else {
                                        echo $comment['Profileslatecomment']['comment'];
                                    }
                                    ?>  
                                </div>
                                <?php
                                    $tots = ClassRegistry::init('Profileslatecommentlike')->find('all', array('conditions' => array('Profileslatecommentlike.profileslatecomment_id' => $comment['Profileslatecomment']['id']), 'recursive' => -1));

                                    $tot = sizeof($tots);
                                    //$tot = $wallcommentLike->countwallcommentlikes($comment['Profileslatecomment']['id']);
                                    ?> 
                                <div class="tar fnt80"><span
                                        onclick="<?php echo $fun_n?> &nbsp;('<?php echo $ww_root?>profileslatecommentlikes','<?php echo $comment['Profileslatecomment']['id']; ?>',<?php echo $tot;?>)"
                                        id="<?php echo 'lkunl' . $comment['Profileslatecomment']['id'] ?>"
                                        class="cmlikespid"> <?php echo $lun; ?>(<?php echo $tot; ?>)</span></div>
                            </div>
                        </div>
                    </div>
                </div>
            </li>

            <?php
            endforeach;

            endif;
            ?>
            <div id="moreresults<?php echo $wall['Profileslate']['id']; ?>"
                 class="moreresults<?php echo $wall['Profileslate']['id']; ?>"></div>
            <?php if ($totalComment > 3){
            $view = "view more";
            ?>
            <div style="margin-left: 67px; margin-bottom: 10px; cursor: pointer;  text-align: center;">
                <div class="btn btn-mini" id="morereno<?php echo $wall['Profileslate']['id']; ?>"
                     onclick="getMoreComment<?php echo $i; ?>('<?php echo $wall['Profileslate']['id']?>')"><?php echo $view;?></div>
            </div>

            <?php }?>
            <div style="clear: both;"></div>
        </ul>
        <div style="clear: both;"></div>
    </div>
    <?php
    $i++;
    endforeach;
    ?>
</div>
