<?php

    $limit = @$_REQUEST['limit'] ? @$_REQUEST['limit'] : 10;
    $offset = @$_REQUEST['limit'] ? @$_REQUEST['offset'] : 0;

    $photoLikes = mysql_select("feed", "`section` = 'photo_likes'  ORDER BY `action_date` DESC LIMIT $limit OFFSET $offset");
?>
<?php

    foreach($photoLikes as $photoLike):
        $photoLikeData     = json_decode($photoLike['json'], true);    
        
        if( array_key_exists('listingsNum', $photoLikeData) ){

            $photoLikeData['listings'] = mysql_get('listings', $photoLikeData['listingsNum'], null, "`timezone`,`monday_open`,`monday_close`,`tuesday_open`,`tuesday_close`,`wednesday_open`,`wednesday_close`,`thursday_open`,`thursday_close`,`friday_open`,`friday_close`,`saturday_open`,`saturday_close`,`sunday_open`,`sunday_close`, `latitude`, `longitude`, `address_1`, `name`, `city`, `average_rating`, `checkins`, `cuisine`, `coupons`, `reviews`, `followers`, `num`");
            // add listings recent photos
            $photoLikeData['listings']['recent_photos'] = mysql_select('photo_uploads', "`listingsNum` = ".intval($photoLikeData['listingsNum'])." AND `for_photo` = 'photo' AND `flagged` = 0 ORDER BY `createdDate` DESC LIMIT 0,1");
            foreach($photoLikeData['listings']['recent_photos'] as $photoKey => $photo){ 
              $photoLikeData['listings']['recent_photos'][$photoKey]['photos'] = getUploadRecords('photo_uploads', 'photos' , $photo['num']);
            }
            // add listing close time
            // $photoLikeData['listings'] = api_addOpenCloseDetailsToListing($photoLikeData['listings']);
        }

        if(array_key_exists('membersNum', $photoLikeData)){
            $photoLikeData['members'] = mysql_get('members', $photoLikeData['membersNum'], null, "`facebook_picture`, `facebook_first_name`, `facebook_last_name`, `username`, `num`, `isAdmin`, `points`, `check_ins`, `following`, `followers`, `reviews`");
        }

        // add members pics who liked photo
        $photoLikeData['members_likes_photo'] = mysql_select_join('photo_likes', 'members', "`photo_uploadsNum` = ".intval(@$photoLikeData['photo_uploadsNum']),"membersNum",array('facebook_picture'), 3);

        $photoLikeData['members_likes_count'] = strval(mysql_count('photo_likes', "`photo_uploadsNum` = ".intval(@$photoLikeData['photo_uploadsNum'])));

        $photoLikeData['uploaded_by'] = mysql_select_join('photo_uploads', 'members', "urbanhal_photo_uploads.`num` = ".intval($photoLikeData['photo_uploadsNum']),"membersNum",array('facebook_first_name','facebook_last_name','num'), 1);

        $userName = $photoLikeData['members']['facebook_first_name']." ".$photoLikeData['members']['facebook_last_name'][0];
?>
        
        <div class="feed_section stats_section clearfix">
            <div class="user_info_wrap clearfix" style="margin: 5px 0;">
                <div class="user_img">
                    <img width="30" height="30" src="<?php echo $photoLikeData['members.facebook_picture']; ?>">
                </div>
                <div class="comment_info">
                    <div class="user_name">
                        <span><?php echo $userName ?>.</span>
                    </div>
                    <div class="user_action">
                        <span style="font-size: 12px;">Loves <a style="color:#D93549;"><?php echo @$photoLikeData['uploaded_by'][0]['facebook_first_name']." ".@$photoLikeData['uploaded_by'][0]['facebook_last_name'][0]; ?></a>'s moment</span>
                        <span id="time" style="color: #9b9b9b;font-size: 12px;"><?php echo shortPrettyDate($photoLike['action_date']); ?></span>
                    </div>
                </div>
                <div class="points" style="float: right;">
                    <span class="check_in_icon" style="margin-right: 5px;">
                        <img style="vertical-align: middle;" src="https://s3-us-west-1.amazonaws.com/urban-halal/email-newsletter/images/camera-small.png">
                    </span>
                    <span style="color: #5BBC2E;font-size: 12px;">25 PTS</span>
                </div>
            </div>
            <div class="snapped_img" style="background: url('<?php echo !empty($photoLikeData['photo_uploads.photos']) ? $photoLikeData['photo_uploads.photos'][0]['thumbUrlPath2'] : ''; ?>');background-repeat: no-repeat;background-size: cover;"></div>
            <?php if($photoLikeData['members_likes_count'] > 0): ?>
            <div class="photo_likes_info">

                <div class="likes_user_img_wrap">
                <?php foreach($photoLikeData['members_likes_photo'] as $index => $memberLikedPhoto): ?>
                    <div class='like_user_img' style='float: right;border-radius: 50%;margin-right: <?php echo $index == 0 ? '5' : '-7';?>px;'>
                        <img src="<?php echo $memberLikedPhoto['facebook_picture']; ?>"/>
                    </div> 
                <?php endforeach; ?>
                </div>
                <span class="likes_count_text">
                <?php echo $photoLikeData['members_likes_count']; ?>
                </span>
            </div>
            <?php endif; ?>
        </div>
        
        <hr style="margin:0;">
<?php
    endforeach;
?>        