
<style>
 i{
    cursor:pointer;
}
</style>

<?php $ww_root=$this->webroot;?>
	<?php 
	$position = $position ?? ''; 
		 if($position){
        	$i = $position+1;
        }else{
        	$i = 1;
        }
		foreach($walllist as $wall): 
		//pr($wall);
			$total_like = sizeof($wall['Walllike']);
			static $i = 1;
			if(empty($wall['Walllike'])):
				$lun = 'Like';
				$fun_n = 'like_by_wall_id';
			else :
				foreach ($wall['Walllike'] as $like):
					if($like['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;
            $totalComment =ClassRegistry::init('Wallcomment')->find('count',array('conditions'=>array('Wallcomment.wall_id'=>$wall['Wall']['id']),'recursive'=>-1));
			if($wall['Wall']['user_id'] == $loggedUser['id']):
				$del = $this->Form->postLink(__("<i class='fa fa-times'></i>"), array('action' => 'delete', $wall['Wall']['id']),array('escape'=>false), null, __('Are you sure you want to delete # %s?', $wall['Wall']['id'])); 
			else:
				$del = '';
			endif;
			?>
			<div class="row-fluid <?php echo 'wall'.$i;?>">
				<div class="single-wall-display cbox">
					<div class="row-fluid wall-post-content">
						<div class="">
							<div class="span1">
								 <?php if(!empty($wall['Prof']['link1'])){?>
	                                   <img src="<?php echo $wall['Prof']['link1'];?>" style=" margin: 5px 0px 0px 14px; border-radius: 50%;">
	                             <?php }else {?> 
	                                   <img src="<?php echo $this->webroot?>img/profile.jpg" style=" margin: 5px 0px 0px 14px; border-radius: 50%;">
	                              <?php }?>	
							</div>
							<div class="span11 prelative">
								<span class="topright"><?php echo $del;?></span>
								<div class="w97p">
									<span class="profile-name mainName">
									<?php echo $this->Html->link($wall['Prof']['fname'].' '.$wall['Prof']['lname'],array('controller'=>'profiles','action'=>'about',base64_encode($wall['Prof']['id'])));?>
									</span>
									<span class="fl cash" style="position: absolute;margin: 24px 20px">
										<?php 
										
										$adte=$wall['Wall']['created'];
										$localtime=timeAgo($wall['Wall']['created']);
										if($localtime=='true'){
											echo getTimeZoneConvert($adte,$timezone);
										}else{
											echo timeAgo($adte);
										}
										
										
											
										?>
									</span>
								</div>
							</div>
						</div>
						<div class="clearfix"></div>
						<div class="span12 prelative" style="margin-left:0px;padding: 17px 17px;  line-height: 1.4;">
								<?php
								if (strlen($wall['Wall']['content'])>1020){
                                      $reading=$this->Html->link('...Continue reading',array('controller'=>'walls','action'=>'view',$wall['Wall']['id']),array('style'=>'color:#5050df'));
                                      echo substr($wall['Wall']['content'],0,1020).$reading;
                                }else {
                                      echo $wall['Wall']['content'];
                                }?>
							<?php 
							//pr($wall);die();
							switch ($wall['Wall']['type']){
								case 1: 
									if(!empty($wall['Wall']['linkfile'])){
										echo 	
										'<div class="ih150 pdt5 mrt5">'.
											"<a href=".$wall['Wall']['linkfile']." download=".$wall['Wall']['linkfile']." class='cblue fnt80' target='_blank'>".$wall['Wall']['filename']."</a>".
										'</div>';
									}
									break;
								case 2:
									if(!empty($wall['Wall']['link1'])){echo '<div class="ih150  pdt5 mrt5 tac">'."<a href=".$wall['Wall']['link2']." data-lightbox='example-set' class='cblue fnt80 example-image-link'>"."<img  src=".$wall['Wall']['link1'].">"."</a>".'</div>';}
									break;
								case 3:
									if(!empty($wall['Wall']['link2'])){
										$wall_meta = '';
										if(!empty($wall['Wall']['meta'])){
											$wall_meta = $wall['Wall']['meta'].'<br/>';
										}
										if (strlen($wall['Wall']['lnk'])>100){
											$sitelink=$this->Html->link(substr($wall['Wall']['lnk'],0,100).'....',$wall['Wall']['lnk'],array('target'=>'_blank','class'=>'cblue'));
										}else{
											$sitelink=$this->Html->link($wall['Wall']['lnk'],$wall['Wall']['lnk'],array('target'=>'_blank','class'=>'cblue'));
										}
										echo 	
										'<div class="ih150 pdt5 mrt5">
											<div class="row-fluid">
												<div class="" style="float:left; margin-top: 5px;margin-right: 10px;min-height: 70px;"> '."<a href=".$wall['Wall']['link2']." download=".$wall['Wall']['link2']." class='cblue fnt80' target='_blank'>"."<img  src=".$wall['Wall']['link2'].">"."</a>".'</div>
												<div class="">'.$wall_meta.$sitelink.'</div>
											</div>
										</div>';
									}elseif(!empty($wall['Wall']['meta'])){
									if (strlen($wall['Wall']['lnk'])>100){
											$sitelink=$this->Html->link(substr($wall['Wall']['lnk'],0,100).'....',$wall['Wall']['lnk'],array('target'=>'_blank','class'=>'cblue'));
										}else{
											$sitelink=$this->Html->link($wall['Wall']['lnk'],$wall['Wall']['lnk'],array('target'=>'_blank','class'=>'cblue'));
										}
										echo 	
										'<div class="ih150 pdt5 mrt5">
											<div>'.$wall['Wall']['meta'].'</div>
											<div>'.$sitelink.'</div>
										</div>';
									}else {
										if (strlen($wall['Wall']['lnk'])>100){
                                            $sitelink=$this->Html->link(substr($wall['Wall']['lnk'],0,100).'....',$wall['Wall']['lnk'],array('target'=>'_blank','class'=>'cblue'));
                                        }else {
                                            $sitelink=$this->Html->link($wall['Wall']['lnk'],$wall['Wall']['lnk'],array('target'=>'_blank','class'=>'cblue'));
                                        }
                                        echo 	
                                           '<div class="ih150 pdt5 mrt5 fnt80">
                                                <div>'.$sitelink.'</div>
                                           </div>';
									}
									break;
								case 4:
									if(!empty($wall['Wall']['lnk'])){
										?>
										<div class=" ih150 pdt5 mrt5">
                                                                <?php 
                                                                $vdImg = explode("watch?v=",$wall['Wall']['lnk']);
                                                                ?>
                                                                <div id="Ytvd_<?php echo $wall['Wall']['id'];?>"></div>
                                                                <div class="row-fluid" >
                                                                <?php if (!empty($wall['Wall']['link2'])){?>
                                                                    <div id="vdoImg_<?php echo $wall['Wall']['id'];?>" class="" style="width:18%; float: left;">
                                                                        <a href="javascript:;" class="fileLink prelative" onclick="_vd('<?php echo $vdImg[1];?>','<?php echo $wall['Wall']['id'];?>')">
                                                                            <i class="fa fa-play fa-2x pmiddle"></i>
                                                                            <img src="<?php echo $wall['Wall']['link2']; ?>" />
                                                                        </a>
                                                                    </div>
                                                                    <?php }?>
                                                                    <div class="fnt80" style="width: 93%;">
                                                                        <div><?php echo $wall['Wall']['meta'];?></div>
                                                                        <div><?php
                                                                           if (strlen($wall['Wall']['lnk'])>60){ 
                                                                                echo $this->Html->link(substr($wall['Wall']['lnk'],0,60).'....',$wall['Profileslate']['lnk'],array('target'=>'_blank','escape'=>false,'class'=>'cblue'));
                                                        			}else {
                                                        				echo $this->Html->link($wall['Wall']['lnk'],$wall['Wall']['lnk'],array('target'=>'_blank','escape'=>false,'class'=>'cblue'));
                                                        			}
                                                        			?>
                                                        		</div>
                                                                    </div>
                                                                </div>
                                                	</div>
										<?php
											}
										?>
									<?php 
										break;
										}
									?>
							<div class="tar pdt5 mrt5 pdr5"> 
								<span onclick="<?php echo $fun_n?>('<?php echo $ww_root?>walllikes','<?php echo $wall['Wall']['id'] ?>',<?php echo $total_like;?>);"id="<?php echo 'lun'.$wall['Wall']['id'] ?>" style="cursor:pointer; margin-right:7px;"><?php echo $lun . '('.$total_like.')'?>
								</span>
								<span id="btnComment<?php echo $i;?>" onclick="addFrm(<?php echo $i;?>,<?php echo $wall['Wall']['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 ml60" style="display: none;"></div>
					<div id="newcomment<?php echo $i; ?>"></div>
					<?php
						$arr_comments =ClassRegistry::init('Wallcomment')->find('all',array('conditions'=>array('Wallcomment.wall_id'=>$wall['Wall']['id']),'recursive'=>-1,'limit'=>3,'order'=>'Wallcomment.id DESC'));
						
						if(sizeof($arr_comments)>0):
							$wallcommentLike = ClassRegistry::init('Wallcommentlike');
							foreach ($arr_comments as $comment):
							/*echo '<pre>';
							print_r($comment);
							echo '<pre>';*/
							if($wallcommentLike->checkme($comment['Wallcomment']['id'],$loggedUser['id'])){
								$lun = 'Liked';
								$fun_n = 'unlike_by_wall_id2';
							}else{
								$lun = 'Like';
								$fun_n = 'like_by_wall_id2';
							}
							if($comment['Wallcomment']['user_id'] == $loggedUser['id']):
								$del = 'Delete';
							else:
								$del = '';
							endif;
							?>
							<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+"wallcomments/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>
							
							<div class="single-wall-display ml60 cbox" id="data_<?php echo $comment['Wallcomment']['id'];?>" >
									<div class="row-fluid">
										<div class="" style="width: 7%;float: left;">
										<?php if ($comment['Wallcomment']['parent_id']==0){?>
                                        	<img src="<?php echo $profileInfolink[$comment['Wallcomment']['user_id']];?>" width="50px" height="50px" style="border-radius: 50%">
                                        <?php }elseif(!empty($wall['Prof']['link1'])){?>
                                            <img src="<?php echo $wall['Prof']['link1'];?>" 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="" style="width:93%;position: relative;float: left;padding-left: 1%;line-height: 1.5">
											<?php 
											if(!empty($del)){
												?>
												<div class="topright">
													<i class='fa fa-times'></i><span class="btnn" onclick="dd('wallcomments','delete','<?php echo $comment['Wallcomment']['id']; ?>');"><?php //echo $del;?></span>
												</div>
												<?php
											}
											?>
											<div class="w98p">
												<span class="profile-name" style="float: left;width: 100%">
													<?php echo $this->Html->link($profileInfo[$comment['Wallcomment']['user_id']],array('controller'=>'profiles','action'=>'about',base64_encode($comment['Wallcomment']['user_id'])));?>
												</span>
												<span class="fl fnt80 cash" style="width: 100%"><?php 
												
												$adte=$comment['Wallcomment']['created'];
												$localtime=timeAgo($comment['Wallcomment']['created']);
												if($localtime=='true'){
													echo getTimeZoneConvert($adte,$timezone);
												}else{
													echo timeAgo($adte);
												}?> 
												</span> 
			                                </div>
			                                  <div class="w100p fnt80">
												<?php 
                                                     if (strlen($comment['Wallcomment']['comment'])>260){
                                                         $reading=$this->Html->link('...Continue reading',array('controller'=>'wallcomments','action'=>'view',$comment['Wallcomment']['id']),array('style'=>'color:#5050df'));
                                                         echo substr($comment['Wallcomment']['comment'],0,260).$reading;
                                                     }else {
                                                         echo $comment['Wallcomment']['comment'];
                                                     }
                                                     $tot = $wallcommentLike->countwallcommentlikes($comment['Wallcomment']['id']);
                                                 ?>
											</div>
											<div class="mrt5 pdt5 pdr5"> 
												<div class="small-like" onclick="<?php echo $fun_n?>('<?php echo $ww_root?>wallcommentlikes','<?php echo $comment['Wallcomment']['id']; ?>',<?php echo $tot;?>)"id="<?php echo 'lkunl'.$comment['Wallcomment']['id'] ?>" style="cursor:pointer;"> <?php echo $lun; ?>(<?php echo $tot;?>)</div>
											</div> 
										</div>
									</div>
							</div>
							<?php
						endforeach;
					endif;
					?>
					<div id="moreresults<?php echo $wall['Wall']['id']; ?>" class="moreresults<?php echo $wall['Wall']['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['Wall']['id']; ?>"  onclick="getMoreComment<?php echo $i; ?>('<?php echo $wall['Wall']['id']?>')"><?php echo $view;?></div>
                        	</div>
                       
                       <?php }?>
					
			</div>
		<?php 
		$i++;
		endforeach;
		?>	
