<?php
if(isset($nearby_places) && is_array($nearby_places) && count($nearby_places) > 0) {
    $optres['css'][] = $module_css_path . 'amodules/nearby_places/css/nearby_places_default.css';
    $optres['js'][] = $path . 'assets/js/masonry.pkgd.min.js';
    $optres['js'][] = $path . 'amodules/nearby_places/js/nearby_places_default.js';
	?>
	<section class="box box-primary">
		<header class="box-header with-border">
            <b>Nearby Places Of Interest</b>
        </header>
		<div class="box-body">
            <div class="nearby_places_grid">
                <div class="nearby_places_sizer"></div>

                <?php
                $k=0;
                foreach ($nearby_places as $i=>$article) {
                    $disp_url = trim(stripslashes($article['url'])) != "" ? fix_url(trim(stripslashes($article['url']))) : '';
                    $disp_href = "article/" . $article['friendly_url'] . ".html";

                    $href = $disp_url != "" ? $disp_url : $disp_href;

                    $disp_target = ($article['_blank'] == "yes") ? '_blank' : '_self';
                    $disp_node = "";
                    $disp_title = $article['title_en'];

                    $art_photos = null;
                    $q = "select * from main_article_images where article_id='".$article['article_id']."' order by pos asc limit 0,1;";
                    $r = @mysql_query($q);
                    if($r && mysql_num_rows($r) > 0) {
                        while ($row = mysql_fetch_assoc($r)) {
                            $art_photos = array_map("stripslashes", $row);
                        }
                    }

                    //echo '<pre>', var_export($art_photos, true), '</pre>';

                    ob_start();
                    ?>
                    <div class="nearby_places_item" itemscope="itemscope" itemtype="http://schema.org/<?php echo ($article['a_type'] == "poi") ? 'TouristAttraction' : 'Article';?>">
                        <div class="nearby_places_item_container">
                            <?php

                            ?>
                            <div class="nearby_title">
                                <?php
                                if(isset($_SESSION['user_id']) && intval($_SESSION['user_id']) > 0) {
                                    echo '<div class="user-action-container"><a class="user-action-inline" href="/admin/index.php?plugin=contents&amp;action=article&amp;article_id='.$article['article_id'].'" target="_blank">e</a></div>';
                                }
                                echo '<a href="', ($disp_url == "" ? $full_addon_uri . $disp_href : $disp_url) ,'" target="', $disp_target, '" title="', $disp_title,'" class="nearby_place_title" itemprop="url"><span itemprop="name">', $disp_title, '</span></a>';
                                ?>
                            </div>
                            <?php
                            $have_photo = $art_photos != null;
                            $have_abstract = (trim($article['short_descr_en']) != "") ? true : false;

                            if($have_abstract) {
                                ?>
                                <div class="nearby_place_abstract" itemprop="description">
                                    <?php
                                    echo '<p class="nearby_text">';
                                        if($have_photo) {
                                            $thumb_file = dirname(__FILE__) . "/../../images/articles/$domain_id/" . $article['article_id'] . "/gallery/thumbs/" . $art_photos['filename'];
                                            $thumb_url = $protocol . $_SERVER['HTTP_HOST'] . "/images/articles/$domain_id/" . $article['article_id'] . "/gallery/thumbs/" . $art_photos['filename'];
                                            if(file_exists($thumb_file)) {
                                                echo '<a href="', ($disp_url == "" ? $full_addon_uri . $disp_href : $disp_url) ,'" target="', $disp_target, '">';
                                                ?>
                                                <img src="<?php echo $thumb_url; ?>" alt="<?php echo $article['title_en']; ?>" itemprop="image"  width="<?php echo $art_photos['iwt'];?>" height="<?php echo $art_photos['iht'];?>"/>
                                                <?php
                                                echo '</a>';
                                            }
                                        }
                                        else {
                                            echo '<div class="no-nearby-photo"><span></span></div>';
                                        }
                                        //echo $article['short_descr_en'];
                                    echo '</p>';
                                    ?>
                                    <div style="clear: both;"></div>
                                </div>
                                <?php
                            }
                            ?>
                        </div>
                    </div>
                    <?php
                    $np = ob_get_contents();
                    ob_end_clean();
                    echo $np;

                    $k++;
                }


                ?>
            </div>
		</div>
	</section>
	<?php
}
?>