<?php
require_once(__DIR__ . "/../common/video/parse_video_urls.php");
/**
 * get youtube video ID from URL
 *
 * @param string $url
 * @return string Youtube video id or FALSE if none found.
 */
function youtube_id_from_url($url) {
    $pattern =
        '%^# Match any youtube URL
        (?:https?://)?  # Optional scheme. Either http or https
        (?:www\.)?      # Optional www subdomain
        (?:             # Group host alternatives
          youtu\.be/    # Either youtu.be,
        | youtube\.com  # or youtube.com
        | youtube-nocookie\.com  # or youtube-nocookie.com
          (?:           # Group path alternatives
            /embed/     # Either /embed/
          | /v/         # or /v/
          | /watch\?v=  # or /watch\?v=
          )             # End path alternatives.
        )               # End host alternatives.
        ([\w-]{10,12})  # Allow 10-12 for 11 char youtube id.
        $%x'
    ;
    $result = preg_match($pattern, $url, $matches);
    if (false !== $result) {
        return $matches[1];
    }
    return false;
}

if(!function_exists("is_nofollow")) {
    function is_nofollow($nofollow_domains)
    {
        global $domain_id;

        $formated_domain_id = sprintf("%04.0f", $domain_id);

        if (strpos($nofollow_domains, $formated_domain_id) !== false) return true;

        return false;
    }
}

$show_featured_adverts_domains = array(
    "cyprus-parking.com",
    "cyprusservices.com"
);
//if( in_array(str_replace("www.", "", $ultra_domainname), $show_featured_adverts_domains)) {
if (CF_PAGE_INFO_ADVERTS != "no") {

    if (CF_PAGE_INFO_ADVERTS == "all") {
        $module_show_featured_title = 0;
        $module_show_featured_section = 1;
        $module_show_secondary_section = 1;
    }

    if (CF_PAGE_INFO_ADVERTS == "primary") {
        $module_show_featured_title = 0;
        $module_show_featured_section = 1;
        $module_show_secondary_section = 0;
    }

    if (CF_PAGE_INFO_ADVERTS == "secondary") {
        $module_show_featured_title = 0;
        $module_show_featured_section = 0;
        $module_show_secondary_section = 1;
    }

    //$rel_nofollow = 1;
    require_once(dirname(__FILE__) . "/../adverts/adverts_o.php");
}

require_once($general_path . "microdata_pool.php");

if(in_array(str_replace('www.', '', $ultra_domainname), $special_domains) ) {
    $left_pool_empty = true;
}

$authorized_advert = false;
$paying_advert = false;

// New Seo
$seo = true;

if (str_replace("www.", "", $ultra_domainname) == "cyprus-hotel.com") {
    $seo = true;
}

$send404 = isset($send404) ? $send404 : false;
$adv_code = trim($linePopup['adv_code']);
$video = trim($linePopup['video']);
$wb_domainname = str_replace('www.', '', $ultra_domainname);

// Validate if the advert should show
// Get Advert status
/*$advert_status = $linePopup['active'] == "yes" ? 1 : 0;
$wb_status = 0;

// Get advert categories
$advert_categs = array();
$qc = "SELECT
        a.wb_status,
        a.wb_uid,
        a.wb_main,
        a.wb_params
    FROM
      wb_categories_adverts a,
      wb_categories_domains d
    WHERE
      a.wb_uid=d.wb_uid
      AND a.wb_advert_uid='$adv_code'
      AND d.wb_domainname='$wb_domainname';";
$rc = mysql_query($qc) or die("<strong>$qc</strong>".mysql_error());
if($rc && mysql_num_rows($rc)>0) {
    $rowc = mysql_fetch_assoc($rc);
    $wb_status = intval($rowc['wb_status']);
}

if($advert_status == 0 && $wb_status == 0) {
    $send404 = true;
}*/

if (!$send404) {
    $webpage_title_en = stripslashes($linePopup['short_title_en']);
    $nofollow = intval($linePopup['nofollow']);
    $nofollow_domains = $linePopup['nofollow_domains'];
    $meta_params = array(
        "company" => stripslashes($linePopup['short_title_en']),
        "location" => "",
        "category" => stripslashes(trim($domain_content_title))
    );

    $meta['keywords'] = stripslashes($linePopup['short_title_en']) . ', ' . $meta['keywords'];

    $meta_replacements = array(
        '[COMPANY]',
        '[LOCATION]',
        '[CATEGORY]'
    );

//$optres ['css'][] = $path . "client_stand.css";
    $optres ['css'][] = $module_css_path . "amodules/client_stand/css/client_stand_default.css";
    $optres ['css'][] = $path . "assets/css/client_stand.css";
    $optres ['css'][] = $path . "css/prettyPhoto.css";
    $optres ['js'][] = $path . "js/jquery.prettyPhoto.js";

    $optres ['css'][] = $path . "assets/css/bootstrap-dialog.min.css";
    $optres ['js'][] = $path . "assets/js/bootstrap-dialog.min.js";

    $optres ['js'][] = $path . "amodules/client_stand/js/client_stand_default.js";


    $meta_loc = "";

    $meta_phrase = "[COMPANY] is a Cyprus business located in [LOCATION]. It is operating in the field of [CATEGORY]";

    if ($ultra_domainname == "www.cyprusnet.com") {
        $meta_phrase = "[COMPANY] is a Cyprus business located in [LOCATION]. It is listed in our [CATEGORY]";
        $webpage_title_en = $webpage_title_en . " | CyprusNet.com";
    }

    $advert_meta_description = trim(stripslashes($linePopup["meta_description"]));
    $advert_meta_keywords = trim(stripslashes($linePopup["meta_keywords"]));
    $advert_use_meta = intval($linePopup["use_meta"]);

    $microdata_domain = str_replace("www.", "", $ultra_domainname);
    $microdata_host = $_SERVER['HTTP_HOST'];
    if (str_replace('www.', '', $microdata_host) != str_replace('www.', '', $ultra_domainname)) {
        $microdata_host .= "/" . $ultra_addonname;

        require_once("../ageneral/functions.php");
    } else {
        require_once($general_path . "functions.php");
    }
    $show_full_microdata = false;
    $microdata = $microdata_types['default'];
    $schema_types = trim($linePopup['schema_types']) != "" ? json_decode(stripslashes($linePopup['schema_types']), true) : null;

    if(isset($_REQUEST['debug_schema'])) echo '<pre>$schema_types = ', var_export($schema_types, true), '</pre>';

    $have_microdata = (isset($microdata_domains) && in_array($microdata_domain, $microdata_domains));
    if ($have_microdata) {
        $show_full_microdata = true;
        $microdata = $microdata_types[$microdata_domain];
    }
    else $have_microdata = true;

    if($schema_types) {
        $st_acc = false;
        foreach($schema_types as $st) {
            if(!$st_acc && $st['default'] == true) {
                $microdata['adverts']['type'] = $st['url'];
                $st_acc = true;
            }

            if($st['domains']) {
                foreach($st['domains'] as $st_domain_id=>$st_domainname) {
                    if($st_domainname == $ultra_domainname) {
                        $st_acc = true;
                        $microdata['adverts']['type'] = $st['url'];
                    }
                }
            }
        }
    }

    if(isset($_REQUEST['debug_schema'])) echo '<pre>$microdata = ', var_export($microdata, true), '</pre>';

// Get domain catdoms
    $catdoms = array();
    $catdoms_idx = array();
    $wb_uid = "";
    $catdoms [] = $domain_id;
    $catdoms_idx [] = "'" . sprintf("%04.0f", $domain_id) . "'";
    $result_sub = mysql_query("SELECT * FROM  domaincategories WHERE parent_id='$domain_id';");
    if (mysql_num_rows($result_sub) <> 0) {
        while ($line_sub = mysql_fetch_array($result_sub)) {
            $catdoms [] = intval($line_sub["catdom_id"]);
            $catdoms_idx [] = "'" . sprintf("%04.0f", $line_sub["catdom_id"]) . "'";

            if (isset($town_friendly_url) && $town_friendly_url == $line_sub['friendly_url']) {
                $town_catdom_id = intval($line_sub['catdom_id']);
            }

        }
    }

// Get domain category
    $q = "SELECT * FROM wb_categories_domains WHERE wb_domainname='" . (str_replace("www.", "", $ultra_domainname)) . "';";
    $r = @mysql_query($q);
    if ($r && mysql_num_rows($r) == 1) {
        $row = mysql_fetch_assoc($r);
        $wb_uid = $row['wb_uid'];
    }


// Check if advert belongs to this category
    $category_advert = false;
    if (isset($wb_uid) && strlen($wb_uid) == 16) {
        $q = "select * from wb_categories_adverts where wb_uid='$wb_uid' and wb_advert_uid='{$linePopup['adv_code']}';";
        if (isset($_REQUEST['debug'])) echo "<br/>$q";
        $r = @mysql_query($q);
        if ($r && mysql_num_rows($r) == 1) {
            $row = mysql_fetch_assoc($r);
            $wb_status = intval($row['wb_status']);
            $wb_main = intval($row['wb_main']);

            if ($wb_status == 1) {
                $authorized_advert = true;

            }

            if ($wb_main == 1) $category_advert = true;
        }
    }

// Check if advert has been bound to the domain
    $q = "select * from domain_advertisment where catdom_id in (" . implode(", ", $catdoms) . ") and advertisment_id='{$linePopup['advertisment_id']}';";
    $r = @mysql_query($q);
    if ($r && mysql_num_rows($r) > 0) {
        $authorized_advert = true;
    }

// GEt catdom_id from advert
    $q = "select * from advertisment where advertisment_id='{$linePopup['advertisment_id']}';";
    $r = @mysql_query($q);
    if ($r && mysql_num_rows($r) == 1) {
        $row = mysql_fetch_assoc($r);
        $bound_catdom = $row['catdom_id'];
        if (trim($bound_catdom) != "") {
            $bcd = explode(";", $bound_catdom);

            if (is_array($bcd) && count($bcd) > 0) {
                foreach ($bcd as $i => $bcatdom) {
                    $bcatdom_id = intval($bcatdom);
                    if (in_array($bcatdom_id, $catdoms)) $authorized_advert = true;
                }
            }
        }
    }


    if ($category_advert) {
        // Get Main category and filter values *******************************************/
        $fm_uid = isset($fm_uid) ? $fm_uid : "";
        if ($fm_uid == "") {
            $q = "select * from wb_filters_adverts_categs where wb_uid='$wb_uid' and adv_code='$adv_code';";
            $r = @mysql_query($q);
            if ($r && mysql_num_rows($r) == 1) {
                $row = mysql_fetch_assoc($r);
                $fm_uid = trim($row['fm_uid']);
            }
        }

        $fmains = array();
        $fcategs = array();
        $felems = array();
        $elms = array();

        $q = "select * from wb_filters_mains where wb_uid='$wb_uid' order by pos asc;";
        $r = @mysql_query($q);
        if ($r && mysql_num_rows($r) > 0) {
            while ($row = mysql_fetch_assoc($r)) {
                $fmains [$row['fm_uid']] = array_map('stripslashes', $row);
            }
        }


        if ($fm_uid != "") {

            $q = "select * from wb_filters_categs where wb_uid='$wb_uid' and fm_uid='$fm_uid' order by pos asc;";
            $r = @mysql_query($q);
            if ($r && mysql_num_rows($r) > 0) {
                while ($row = mysql_fetch_assoc($r)) {
                    if (!isset($fcategs[$row['fm_uid']])) {
                        $fcategs[$row['fm_uid']] = array();
                        $fcategs[$row['fm_uid']][$row['fc_uid']] = array_map('stripslashes', $row);
                    } else {
                        $fcategs[$row['fm_uid']][$row['fc_uid']] = array_map('stripslashes', $row);
                    }

                }
            }

            $q = "select * from wb_filters_elems where wb_uid='$wb_uid'  and fm_uid='$fm_uid' order by fc_uid asc, pos asc;";
            $r = @mysql_query($q);
            if ($r && mysql_num_rows($r) > 0) {
                while ($row = mysql_fetch_assoc($r)) {
                    $elms[$row['e_name']] = array(
                        'wb_uid' => $row['wb_uid'],
                        'fm_uid' => $row['fm_uid'],
                        'fc_uid' => $row['fc_uid'],
                        'fe_uid' => $row['fe_uid'],
                    );

                    if (!isset($felems [$row['fc_uid']])) {
                        $felems [$row['fc_uid']] = array();
                        $felems [$row['fc_uid']][] = array_map('stripslashes', $row);
                    } else {
                        $felems [$row['fc_uid']][] = array_map('stripslashes', $row);
                    }
                }
            }


            // Get already existing values
            $fvalues = array();

            $q = "select * from wb_filters_adverts where wb_uid='$wb_uid' and fm_uid='$fm_uid' and adv_code='$adv_code';";
            $r = @mysql_query($q);
            if ($r && mysql_num_rows($r) > 0) {
                while ($row = mysql_fetch_assoc($r)) {
                    if (isset($fvalues [$row['fe_uid']])) {
                        $fvalues [$row['fe_uid']][] = stripslashes(trim($row['f_value']));
                    } else {
                        $fvalues [$row['fe_uid']] = array();
                        $fvalues [$row['fe_uid']][] = stripslashes(trim($row['f_value']));
                    }
                }
            }
        }
    }
    /****************************************************/

    $specific_locations = array();

// Check if advert is supposed to show because of active bindings
    $q = "select * from domain_advertisment where advertisment_id='{$linePopup['advertisment_id']}' and catdom_id IN (" . implode(",", $catdoms) . ");";
    if (isset($_REQUEST['debug'])) echo "<br/>$q";
    $r = @mysql_query($q);
    if ($r && mysql_num_rows($r) > 0) {
        $authorized_advert = true;
        while ($row = mysql_fetch_assoc($r)) {

            if ($row['params'] != "") {
                $adv_params = unserialize(base64_decode($row['params']));
                if (isset($adv_params['locations']) && is_array($adv_params['locations']) && count($adv_params['locations']) > 0) {
                    $specific_locations [$row['catdom_id']] = $adv_params['locations'];
                }
            }

            if ($row['category_top'] == "yes" || $row['active'] == "yes") {
                $paying_advert = true;
            }
        }
    }

    if (str_replace('www.', '', $ultra_domainname) == "cyprusnet.com") $authorized_advert = true;

    if (isset($_REQUEST['debug'])) echo "<br/>authorized_advert=" . var_dump($authorized_advert);

    if ($authorized_advert) {
        $advertisment_id = $linePopup['advertisment_id'];
        $active = ($linePopup['active'] == "yes") ? "yes" : "no";
        $website = fix_url(trim($linePopup['website']));
        $thumbshot = trim($linePopup['image']);
        $thumbshot_file = dirname(__FILE__) . "/../../images/advertisments/advert_images/" . trim($linePopup['image']);
        $thumbshot_url = $protocol . $_SERVER['HTTP_HOST'] . "/images/advertisments/advert_images/" . trim($linePopup['image']);
        $has_thumbshot = ($thumbshot != "" && file_exists($thumbshot_file));

        if (isset($_REQUEST['thumb'])) {
            echo '<pre>$thumbshot = ', var_export($thumbshot, true), '</pre>';
            echo '<pre>$thumbshot_file = ', var_export($thumbshot_file, true), '</pre>';
            echo '<pre>$thumbshot_url = ', var_export($thumbshot_url, true), '</pre>';
            echo '<pre>$has_thumbshot = ', var_dump($has_thumbshot), '</pre>';
            echo '<pre>__DIR__ = ', __DIR__, '</pre>';
        }


        $show_website = intval($linePopup['show_website']);
        $shortNameURL = trim($linePopup['title_tr']);

        if (!isset($_SESSION['user_id']) && $paying_advert) {
            mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$linePopup['advertisment_id']}'") or die (mysql_error());
            // e stands for search engine
            count_views('adverts_stats_views', 'advertisment_id', $linePopup['advertisment_id'], $domain_id, '', 'e');

            $_adverts_views [] = array(
                "adv_code" => $linePopup['adv_code'],
                "advertisment_id" => $linePopup['advertisment_id'],
                "domain_id" => $domain_id,
                "catdom_id" => $domain_id,
                "domainname" => $ultra_domainname,
                "date_short" => date("Y-m-d"),
                "date_long" => date("Y-m-d H:i:s"),
                "views" => 1,
                "view_from" => 'e'
            );

        }
        // get locations
        $locations = array();
        $disp_loc = array(
            'Nicosia' => '',
            'Limassol' => '',
            'Larnaca' => '',
            'Paphos' => '',
            'Famagusta' => '',
        );

        if (isset($town_catdom_id) && isset($specific_locations[$town_catdom_id])) {

            if (isset($town_friendly_url)) {
                $webpage_title_en .= " - " . ucwords(str_replace('-', ' ', $town_friendly_url));
            }

            $locs_str = implode(",", $specific_locations[$town_catdom_id]);
            $q = "select * from advertisment_locations where location_id in ($locs_str) and advertisment_id='$advertisment_id' and active='1' order by main_location desc;";
        } else {
            //$q = "select * from advertisment_locations where advertisment_id='$advertisment_id' and active='1' order by main_location desc;";
            $q = "select * from advertisment_locations where advertisment_id='$advertisment_id' and active='1' order by city ASC;";
        }
        //echo $q;

        $r = @mysql_query($q);
        if ($r && mysql_num_rows($r) > 0) {
            while ($row = mysql_fetch_assoc($r)) {
                $ldist = $row['district'];

                if (!isset($disp_loc[$ldist])) {
                    $disp_loc[$ldist] = array();
                }
                $disp_loc[$ldist][$row['location_id']] = $row;
                $locations [$row['location_id']] = $row;
            }
        }

        if (count($locations) > 0) {
            //$disp_loc = $locations;
        }

        if ($paying_advert) {
            $click_count_path = "click_count.php?link={$linePopup["title_tr"]}&amp;type=www&amp;id={$linePopup['advertisment_id']}&amp;domain={$ultra_domainname}&amp;domain_id=$domain_id&amp;window=stand&amp;click_from=e";
        } else {
            $click_count_path = "click_count.php?link={$linePopup["title_tr"]}&amp;type=www&amp;id={$linePopup['advertisment_id']}&amp;domain={$ultra_domainname}&amp;domain_id=$domain_id&amp;window=stand&amp;click_from=e";
        }
        /*
        ?>
        <div <?php echo ($have_microdata) ? 'itemscope="itemscope" itemtype="http://schema.org/'.$microdata_types[$microdata_domain]['adverts']['type'].'"' : '';?>>
        <?php
        */

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

        $canonical_link = $real_path_http . $linePopup["title_tr"];
        $logo_url = $full_uri . "images/advertisments/" . $linePopup['advertisment'];

        $show_gallery = false;
        $images = array();


        // Check to see if we have a gallery version
        $have_gallery_version = false;
        $q = "select * from advertisment_gallery_versions where advertisment_id='$advertisment_id' and domainname='$ultra_domainname'";
        $r = @mysql_query($q);
        if($r && mysql_num_rows($r) > 0) {
            $have_gallery_version = true;
            $show_gallery = true;
            $show_gallery = true;

            $optres['js'][] = $path . 'assets/js/masonry.pkgd.min.js';
            $optres['js'][] = $path . 'assets/js/imagesloaded.pkgd.min.js';

            $optres['css'][] = $path . 'assets/plugins/blueimp/css/blueimp-gallery.css';
            $optres['css'][] = $path . 'assets/plugins/blueimp/css/blueimp-gallery-indicator.css';

            $optres['js'][] = $path . 'assets/plugins/blueimp/js/blueimp-gallery.min.js';
            $optres['css'][] = $module_css_path . "amodules/client_stand/css/gallery.css";
            $optres['js'][] = $path . "amodules/client_stand/js/gallery.js";


            $photo_cnt = 0;
            $domainname_str = str_replace(['www.', '.com', '.com.cy', '.org', '.net', '.info', '.eu'], '', $ultra_domainname);
            while ($row = mysql_fetch_assoc($r)) {

                $photo = array_map("stripslashes", $row);
                $images [$photo_cnt] = [
                    "title" => $photo['title'],
                    "src" => $full_uri . "images/advertisments/gallery/$advertisment_id/$domainname_str/" . $photo['filename'],
                    "src_th" => $full_uri . "images/advertisments/gallery/$advertisment_id/$domainname_str/thumbs/" . $photo['filename'],
                    "main" => $photo_cnt == 0 ? 1 : 0
                ];

                /*if($photo_cnt == 0) {
                    $meta_og['image'] = $images[$photo_cnt]['src'];
                }*/

                $photo_cnt ++;
            }
        }


        if($show_full_microdata && !$have_gallery_version) {
            // Get photos

            $gallery_folder = $path . "images/advertisments/gallery/$advertisment_id";
            $gallery_folder_th = $path . "images/advertisments/gallery/$advertisment_id/thumbs";
            $q = "select * from advertisment_gallery where advertisment_id='$advertisment_id' order by pos asc;";
            $r = @mysql_query($q);
            if($r && mysql_num_rows($r) > 0) {

                $show_gallery = true;
                $optres['js'][] = $path . 'assets/js/masonry.pkgd.min.js';
                $optres['js'][] = $path . 'assets/js/imagesloaded.pkgd.min.js';

                $optres['css'][] = $path . 'assets/plugins/blueimp/css/blueimp-gallery.css';
                $optres['css'][] = $path . 'assets/plugins/blueimp/css/blueimp-gallery-indicator.css';

                $optres['js'][] = $path . 'assets/plugins/blueimp/js/blueimp-gallery.min.js';
                $optres['css'][] = $module_css_path . "amodules/client_stand/css/gallery.css";
                $optres['js'][] = $path . "amodules/client_stand/js/gallery.js";


                $photo_cnt = 0;
                while ($row = mysql_fetch_assoc($r)) {

                    $photo = array_map("stripslashes", $row);
                    $images [$photo_cnt] = [
                        "title" => $photo['title'],
                        "src" => $full_uri . "images/advertisments/gallery/$advertisment_id/" . $photo['filename'],
                        "src_th" => $full_uri . "images/advertisments/gallery/$advertisment_id/thumbs/" . $photo['filename'],
                        "main" => $photo_cnt == 0 ? 1 : 0
                    ];

                    /*if($photo_cnt == 0) {
                        $meta_og['image'] = $images[$photo_cnt]['src'];
                    }*/

                    $photo_cnt ++;
                }
            }
        }

        ?>
        <article class="article cyprus"
                 id="<?=$canonical_link . "#organization";?>" <?php echo ($have_microdata) ? 'itemprop="mainEntity" itemscope="itemscope" itemtype="' . $microdata['adverts']['type'] . '" itemid="#' . $linePopup['title_tr'] . '"' : ''; ?>>
            <header>
                <h1 <?php echo ($have_microdata) ? 'itemprop="name"' : ''; ?>><?=stripslashes($linePopup['short_title_en']);?></h1>
                <?php
                if ($have_microdata) {
                    echo '<meta itemprop="url" content="' . $canonical_link . '"/>';
                    echo '<meta itemprop="logo" content="' . $logo_url . '"/>';
                    echo '<meta itemprop="priceRange" content="€€"/>';

                }
                ?>
                <!--[/SocialShareButtons/]-->
                <?php

                if (isset($_SESSION['user_id'])) {
                    echo '<a class="user-action-inline" href="/admin/advert_manager.php?advert_action=advert_edit_main&advertisment_id=' . $linePopup['advertisment_id'] . '" target="_blank">Edit</a>';
                }
                ?>
            </header>
            <div class="article-body cyprus">
                <div id="website">

                    <?php
                    if ($website != "" && $show_website == 1) {
                        echo '<meta itemprop="sameAs" content="' . $website . '"/>';
                        $rel_advert = 'rel="noopener"';
                        if(is_nofollow($nofollow_domains)) $rel_advert = 'rel="nofollow noopener"';

                        if ($active == "yes") {

                            if ($paying_advert) {
                                ?>
                                <a href="click_count.php?link=<?php echo $linePopup["title_tr"]; ?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id']; ?>&amp;domain=<?php echo $ultra_domainname; ?>&amp;domain_id=<?php echo $domain_id; ?>&amp;window=stand&amp;click_from=e"
                                   target="_blank" <?=$rel_advert;?>  class="click-count btn btn-darkred btn-xs btn-flat"
                                   title="<?php echo stripslashes($linePopup['short_title_en']); ?>"><i
                                        class="fa fa-external-link"></i> Visit Website</a>
                                <?php
                            } else {
                                ?>
                                <a href="click_count.php?link=<?php echo $linePopup["title_tr"]; ?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id']; ?>&amp;domain=<?php echo $ultra_domainname; ?>&amp;domain_id=<?php echo $domain_id; ?>&amp;window=stand&amp;click_from=e"
                                   target="_blank" <?=$rel_advert;?> class="btn btn-darkred btn-xs btn-flat"
                                   title="<?php echo stripslashes($linePopup['short_title_en']); ?>"><i
                                        class="fa fa-external-link"></i> Visit Website</a>
                                <?php
                            }
                        } else {
                            ?>
                            <a href="click_count.php?link=<?php echo $linePopup["title_tr"]; ?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id']; ?>&amp;domain=<?php echo $ultra_domainname; ?>&amp;domain_id=<?php echo $domain_id; ?>&amp;window=stand&amp;click_from=e"
                               target="_blank" <?=$rel_advert;?> class="btn btn-darkred btn-xs btn-flat"
                               title="<?php echo stripslashes($linePopup['short_title_en']); ?>"><i
                                    class="fa fa-external-link"></i> Visit Website</a>
                            <?php
                        }

                    }


                    //if($website != "" && $active == "yes" && trim($linePopup['email']) != "") echo " | ";
                    if ($linePopup['email']) {
                        echo ($have_microdata) ? '<meta itemprop="email" content="' . $linePopup['email'] . '">' : '';
                        ?> <a href="#" class="mailto btn btn-info btn-xs btn-flat"
                             rel="<?php echo str_replace('@', '[ at ]', $linePopup['email']); ?>"><i
                                class="fa fa-envelope"></i> Send Email</a> <?php
                    }

                    if (trim($linePopup['email2']) != "") {
                        ?> <a href="#" class="mailto btn btn-info btn-xs btn-flat"
                             rel="<?php echo str_replace('@', '[ at ]', $linePopup['email2']); ?>"><i class="fa fa-envelope"></i> Send Email</a> <?php
                    }
                    ?>
                </div>
                <?php
                $video = trim($linePopup['video']);
                if($video != "" && $show_full_microdata) {
                    $video_id = get_youtube_id($video);
                    $video_embed_url = "//www.youtube-nocookie.com/embed/$video_id?rel=0&amp;showinfo=0";
                    /*
                    <iframe width="560" height="315" src="https://www.youtube.com/embed/V51Edo99ivo?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
                    */
                    ?>
                    <div class="default-video">
                        <div class="embed-responsive embed-responsive-16by9">
                            <div class="youtube_player" videoID="<?=$video_id;?>" width="100%" height="auto" theme="light" rel="0" controls="1" showinfo="0" autoplay="0"></div>
                            <!--<iframe class="embed-responsive-item" src="<?/*=$video_embed_url;*/?>>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>-->
                        </div>
                    </div>
                    <?php
                }

                ?>
                <div id="description">

                    <div id="img" class="pull-right"><?php
                        if ($website != "") {
                            if ($active == "yes") {
                                if ($paying_advert) {
                                    if ($seo && $show_website == 1) {
                                        ?>
                                        <span class="click-link">
                                            <?php
                                            if ($has_thumbshot) {
                                                ?>
                                                <img
                                                    src="<?php echo $thumbshot_url; ?>"
                                                    width="200" height="150" border="1"
                                                    alt="<?php echo $linePopup['short_title_en']; ?>"
                                                    class="img img-thumbnail"
                                                    itemprop="image"/>
                                                <?php
                                            } else {
                                                ?>
                                                <img
                                                    src="<?= $screenshot_url ?>w=200&h=150&url=<?php echo urlencode($website); ?>"
                                                    width="200" height="150" border="1"
                                                    alt="<?php echo $linePopup['short_title_en']; ?>"
                                                    class="img img-thumbnail"
                                                    itemprop="image"/>
                                                <?php
                                            }
                                            ?>
                                        </span>
                                        <?php
                                    } else {
                                        if ($show_website == 1) {
                                            ?>
                                            <a href="click_count.php?link=<?php echo $linePopup["title_tr"]; ?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id']; ?>&amp;domain=<?php echo $ultra_domainname; ?>&amp;domain_id=<?php echo $domain_id; ?>&amp;window=stand&amp;click_from=e" class="click-count" target="_blank" <?=$rel_advert;?> title="<?php echo stripslashes($linePopup['short_title_en']); ?>">
                                            <?
                                        }

                                        ?>
                                        <?php
                                        if ($has_thumbshot) {
                                            ?>
                                            <img
                                                src="<?php echo $thumbshot_url; ?>"
                                                width="200" height="150" border="1"
                                                alt="<?php echo $linePopup['short_title_en']; ?>"
                                                class="img img-thumbnail"
                                                itemprop="image"/>
                                            <?php
                                        } else {
                                            ?>
                                            <img
                                                src="<?= $screenshot_url; ?>w=200&h=150&url=<?php echo urlencode($website); ?>"
                                                width="200" height="150" border="1"
                                                alt="<?php echo $linePopup['short_title_en']; ?>"
                                                class="img img-thumbnail"
                                                itemprop="image"/>
                                            <?php
                                        }
                                        ?>
                                        <?php
                                        if ($show_website == 1) {
                                            ?>
                                            </a>
                                            <?php
                                        }
                                    }
                                } else {
                                    if ($seo && $show_website == 1) {
                                        ?>
                                        <span class="click-link">

                                            <?php
                                            if ($has_thumbshot) {
                                                ?>
                                                <img
                                                    src="<?php echo $thumbshot_url; ?>"
                                                    width="200" height="150" border="1"
                                                    alt="<?php echo $linePopup['short_title_en']; ?>"
                                                    class="img img-thumbnail"
                                                    itemprop="image"/>
                                                <?php
                                            } else {
                                                ?>
                                                <img
                                                    src="<?= $screenshot_url; ?>w=200&h=150&url=<?php echo urlencode($website); ?>"
                                                    width="200" height="150" border="1"
                                                    alt="<?php echo $linePopup['short_title_en']; ?>"
                                                    class="img img-thumbnail"
                                                    itemprop="image"/>
                                                <?php
                                            }
                                            ?>
                                        </span>
                                        <?php
                                    } else {
                                        ?>
                                        <a href="javascript:;">
                                            <?php
                                            if ($has_thumbshot) {
                                                ?>
                                                <img
                                                    src="<?php echo $thumbshot_url; ?>"
                                                    width="200" height="150" border="1"
                                                    alt="<?php echo $linePopup['short_title_en']; ?>"
                                                    class="img img-thumbnail"
                                                    itemprop="image"/>
                                                <?php
                                            } else {
                                                ?>
                                                <img
                                                    src="<?= $screenshot_url; ?>w=200&h=150&url=<?php echo urlencode($website); ?>"
                                                    width="200" height="150" border="1"
                                                    alt="<?php echo $linePopup['short_title_en']; ?>"
                                                    class="img img-thumbnail"
                                                    itemprop="image"/>
                                                <?php
                                            }
                                            ?>
                                        </a>
                                        <?php
                                    }
                                }
                            } else {
                                if ($seo && $show_website == 1) {
                                    ?>
                                    <span class="click-link">
                                    <?php
                                    if ($has_thumbshot) {
                                        ?>
                                        <img
                                            src="<?php echo $thumbshot_url; ?>"
                                            width="200" height="150" border="1"
                                            alt="<?php echo $linePopup['short_title_en']; ?>"
                                            class="img img-thumbnail"/>
                                        <?php
                                    } else {
                                        ?>
                                        <img
                                            src="<?= $screenshot_url; ?>w=200&h=150&url=<?php echo urlencode($website); ?>"
                                            width="200" height="150" border="1"
                                            alt="<?php echo $linePopup['short_title_en']; ?>"
                                            class="img img-thumbnail"/>
                                        <?php
                                    }
                                    ?>
                                </span>
                                    <?php
                                } else {
                                    ?>
                                    <a href="javascript:;">
                                        <img
                                            src="<?= $screenshot_url; ?>w=200&h=150&url=<?php echo urlencode($website); ?>"
                                            width="200" height="150" border="1"
                                            alt="<?php echo $linePopup['short_title_en']; ?>"/>
                                    </a>
                                    <?php
                                }
                            }
                        }
                        ?>
                    </div>
                    <div id="description_content" <?php echo ($have_microdata) ? 'itemprop="description"' : ''; ?>>
                        <?php
                        $advert_desc_text = stripslashes(trim($linePopup['description_en']));
                        $qv = "select * from advertisment_versions where advertisment_id='$advertisment_id' and domainname='$ultra_domainname';";
                        if (isset($_REQUEST['debugv'])) {
                            echo "<br/>$qv";
                        }
                        $rv = @mysql_query($qv);
                        if ($rv && mysql_num_rows($rv) == 1) {
                            $rowv = mysql_fetch_assoc($rv);

                            $advert_desc_text = trim(stripslashes($rowv['description_en']));
                            $advert_meta_description_v = trim(stripslashes($rowv['meta_description_en']));
                            $advert_meta_keywords_v = trim(stripslashes($rowv['meta_keywords_en']));

                            if ($advert_meta_description_v != "") $advert_meta_description = $advert_meta_description_v;
                            if ($advert_meta_keywords_v != "") $advert_meta_keywords = $advert_meta_keywords_v;
                        }

                        //$advert_desc_text = str_replace(array('<br />', '<br>', '<br/>', '<br >'), '<p></p>', nl2br($advert_desc_text));
                        //$advert_desc_text = str_replace(array('Â'), '', nl2br($advert_desc_text));


                        mb_detect_order(array('UTF-8', 'ASCII', 'ISO-8859-1'));

                        //echo mb_convert_encoding($advert_desc_text, "UTD-8");
                        echo html_entity_decode($advert_desc_text);
                        ?>
                    </div>
                </div>

                <?php
                if($show_gallery) {
                    ?>
                    <div class="gallery">
                        <!-- The Gallery as lightbox dialog, should be a child element of the document body -->
                        <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls">
                            <div class="slides"></div>
                            <h3 class="title"></h3>
                            <a class="prev">‹</a>
                            <a class="next">›</a>
                            <a class="close">×</a>
                            <a class="play-pause"></a>
                            <ol class="indicator"></ol>
                        </div>

                        <div id="business-gallery-links" class="business-gallery-images <?php echo (count($images) == 1) ? 'single' : '';?>" data-business-gallery="business-gallery">
                            <div class="business-unit-sizer"></div>
                            <?php
                            foreach($images as $img) {
                                if ($img['main'] == 1) {
                                    if(!isset($meta_og['image'])) $meta_og['image'] = array();
                                    if(!is_array($meta_og['image']) && trim($meta_og['image']) != "") {
                                        $meta_og['image'] = array($meta_og['image']);
                                    }
                                    $meta_og['image'][] = [
                                        "url" => $img['src'],
                                        "alt" => $webpage_title_en . ": " . $img['title']
                                    ];
                                    ?>
                                    <meta itemprop="image" content="<?=$img['src'];?>">
                                    <div class="business-unit business-unit-th">
                                        <div class="business-unit-content">
                                            <a href="<?=$img['src'];?>" title="<?=$img['title'];?>">
                                                <img src="<?=$img['src_th'];?>" alt="<?=$img['title'];?>">
                                            </a>
                                        </div>
                                    </div>
                                    <?php
                                }
                                else {
                                    $meta_og['image'][] = [
                                        "url" => $img['src'],
                                        "alt" => $img['title']
                                    ];
                                    ?>
                                    <div class="business-unit business-unit-th">
                                        <div class="business-unit-content">
                                            <a href="<?=$img['src'];?>" title="<?=$img['title'];?>">
                                                <img src="<?=$img['src_th'];?>" alt="<?=$img['title'];?>">
                                            </a>
                                        </div>
                                    </div>
                                    <?php
                                }
                            }
                            ?>
                        </div>
                    </div>
                    <?php
                }
                ?>


                <?php
                if ($category_advert && $fm_uid != "") {
                    ?>
                    <div id="org-details">
                        <?php
                        foreach ($fcategs[$fm_uid] as $fc_uid => $fc) {
                            if (isset($felems[$fc_uid])) {
                                foreach ($felems[$fc_uid] as $i => $fe) {
                                    $req = intval($fe['required']) == 1 ? true : false;
                                    $e_label_admin = $fe['e_label_display'];
                                    $e_type = $fe['e_type'];
                                    $e_name = $fe['e_name'];
                                    $e_id = $fe['e_id'];
                                    $e_class = $fe['e_class'];
                                    $e_style = $fe['e_style'];
                                    $e_db = $fe['e_db'];
                                    $e_def = $fe['e_def'];
                                    $fe_uid = $fe['fe_uid'];

                                    // Get the options
                                    $have_options = false;
                                    $elem = array();
                                    $elem['e_db'] = array();
                                    $options = trim($e_db);
                                    if ($options != "") {
                                        $opts = unserialize(base64_decode($options));
                                        if (is_array($opts)) {
                                            $opts = array_map('stripslashes', $opts);
                                            $have_options = true;
                                        }
                                    }

                                    if ($have_options) $elem['e_db'] = $opts;

                                    if ($have_options) {
                                        $show_advert_amenity_content = false;
                                        ob_start();
                                        //echo '<pre>', var_export($elem['e_db'], true),'</pre>';
                                        ?>
                                        <div style="clear: both"></div>
                                        <?php
                                        if ($fc['friendly_url'] != "default") {
                                            ?>
                                            <h2><?php echo $fc['title']; ?></h2>
                                            <?php
                                        }
                                        ?>
                                        <h2 class="wb_h2"><?php echo $e_label_admin; ?></h2>
                                        <ul class="wb_ul" id="<?php echo $e_name; ?>">
                                            <?php
                                            foreach ($elem['e_db'] as $val => $label) {
                                                if (isset($fvalues[$fe_uid]) && in_array($val, $fvalues[$fe_uid])) {
                                                    ;
                                                    echo '<li>';
                                                    echo $label;
                                                    echo '</li>';
                                                    $show_advert_amenity_content = true;
                                                }
                                            }
                                            ?>
                                            <div style="clear: both;"></div>
                                        </ul>
                                        <div class="clear-all"></div>
                                        <?php

                                        $advert_amenity_content = ob_get_contents();
                                        ob_end_clean();

                                        if ($show_advert_amenity_content) echo $advert_amenity_content;
                                    }


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

                }

                ?>


                <div>
                    <?php
                    if (trim($linePopup['YearOfEstablishment']) != "" || trim($linePopup['Directors']) != ""
                        || trim($linePopup['NumberOfEmployees']) != "" || trim($linePopup['MemberOf']) != ""
                    ) {
                        ?>
                        <div class="row">
                            <div class="col-md-10">
                                <table class="table table-bordered">
                                    <thead>
                                    <tr>
                                        <th class="text-left" colspan="2">Company Information</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    if (trim($linePopup['YearOfEstablishment']) != "") {
                                        ?>
                                        <tr>
                                            <td class="text-bold col-sm-4 col-xs-5">Year of Establishment</td>
                                            <td><?php echo $linePopup['YearOfEstablishment']; ?></td>
                                        </tr>
                                        <?php
                                    }
                                    if (trim($linePopup['Directors']) != "") {
                                        ?>
                                        <tr>
                                            <td class="text-bold col-sm-4 col-xs-5">Directors</td>
                                            <td><?php echo $linePopup['Directors']; ?></td>
                                        </tr>
                                        <?php
                                    }
                                    if (trim($linePopup['MemberOf']) != "") {
                                        ?>
                                        <tr>
                                            <td class="text-bold col-sm-4 col-xs-5">Member of</td>
                                            <td><?php echo $linePopup['MemberOf']; ?></td>
                                        </tr>
                                        <?php
                                    }
                                    if (trim($linePopup['NumberOfEmployees']) != "") {
                                        ?>
                                        <tr>
                                            <td class="text-bold col-sm-4 col-xs-5">Number of Employees</td>
                                            <td><?php echo $linePopup['NumberOfEmployees']; ?></td>
                                        </tr>
                                        <?php
                                    }
                                    ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>

                        <?php
                    }

                    //echo '<pre>', print_r($disp_loc), '</pre>';


                    if (count($disp_loc) > 0) {

                       $cnt = 1;
                        foreach ($disp_loc as $district_group => $district_locations) {
                            if (is_array($district_locations) && count($district_locations) > 0) {
                                echo '<h4 style="color:#C40000; border-bottom: 1px solid #000000;">' . stripslashes($linePopup['short_title_en']) . ' ' . $district_group .'</h4>';
                            }

                            if (isset($_REQUEST['debug_cs'])) {
                                echo '<pre>$disp_loc = ', var_export($disp_loc, true), '</pre>';
                                echo '<pre>', var_export($district_locations, true), '</pre>';
                            }
                            if (is_array($district_locations)) {

                                foreach ($district_locations as $location_id => $data) {
                                    $location_title = trim(stripslashes($data['location_title']));
                                    if ($location_title == "") {
                                        $location_title = "Address $cnt";
                                    } else {
                                        if ($location_title == "Address Details") $location_title .= " #$cnt";
                                    }

                                    $have_map = false;
                                    if (isset($data['lat']) && floatval($data['lat']) > 0) $have_map = true;

                                    ob_start();


                                    $show_postal_address = false;
                                    $schema_postal_address = '';
                                    if($have_microdata) {
                                        $show_postal_address = true;
                                        // Start schema address block
                                        $schema_postal_address = '<div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress">';
                                    }
                                    ?>
                                    <div class="box box-default box-address">
                                        <div class="box-header with-border">
                                            <b><i class="fa fa-map-marker fa-lg"></i> <?php echo $location_title; ?></b>
                                        </div>
                                        <div class="box-body">
                                            <?php
                                            if($have_map) {
                                                ?>
                                                <div class="map-container">
                                                    <div class="map_canvas_static" itemprop="geo" itemscope="itemscope" itemtype="http://schema.org/GeoCoordinates">
                                                        <?php
                                                        if (isset($_REQUEST['page']) && intval($_REQUEST['page']) == 1) {
                                                        ?>
                                                        <a href="<?php echo $protocol . $_SERVER['HTTP_HOST']; ?>/amodules/adverts_map/map_enlarge.php?location_id=<?php echo $location_id; ?>&amp;domain_id=<?php echo $domain_id; ?>" target="_self" rel="nofollow noopener">
                                                            <?php
                                                            }
                                                            else {
                                                            ?>
                                                            <a href="javascript:;" class="map_enlarge_link" rel="<?php echo $location_id; ?>">
                                                                <?php
                                                                }
                                                                $lat = $data['lat'];
                                                                $lng = $data['lng'];
                                                                $zoom = $data['zoom'];

                                                                //$static_map_url = 'http://maps.google.com/maps/api/staticmap?' . ('center=' . $lat . ',' . $lng .'&zoom='.$zoom.'&size=320x240&markers=%7C'.$lat . ',' . $lng.'&sensor=false');
                                                                $static_map_url = 'https://maps.googleapis.com/maps/api/staticmap?key=AIzaSyDxpjfVxlLazmPt1gkiw_wIy55ofWAUJvY&' . ('center=' . $lat . ',' . $lng . '&zoom=' . $zoom . '&size=800x400&maptype=roadmap&markers=%7C' . $lat . ',' . $lng . '&sensor=false');
                                                                //echo '<img src="', $static_map_url, '" class="img img-responsive">';

                                                                ?>
                                                                <picture>
                                                                    <!--[if IE 9]><video style="display: none;"><![endif]-->
                                                                    <source srcset="<?=$static_map_url;?>&size=720x300, <?=$static_map_url;?>&size=720x300&scale=2 2x" media="(min-width: 800px)">
                                                                    <source srcset="<?=$static_map_url;?>&size=720x300, <?=$static_map_url;?>&size=720x300&scale=2 2x">
                                                                    <!--[if IE 9]></video><![endif]-->
                                                                    <img srcset="<?=$static_map_url;?>&size=720x300, <?=$static_map_url;?>&size=720x300&scale=2 2x" class="map_directions_link img-responsive" data-rel="<?=$data['location_id'];?>" alt="<?=stripslashes($linePopup['short_title_en']);?> on map">
                                                                </picture>

                                                                <meta itemprop="latitude" content="<?php echo $lat;?>" />
                                                                <meta itemprop="longitude" content="<?php echo $lng;?>" />

                                                            </a>
                                                    </div>


                                                    <div class="map-controls">

                                                        <?php
                                                        if (isset($_REQUEST['page']) && intval($_REQUEST['page']) == 1) {
                                                            ?>
                                                            <a href="<?php echo $protocol . $_SERVER['HTTP_HOST']; ?>/amodules/adverts_map/map_directions.php?location_id=<?php echo $location_id; ?>&amp;domain_id=<?php echo $domain_id; ?>"
                                                               target="_self"><i class="fa fa-car"></i> Driving
                                                                Directions</a>
                                                            <?php
                                                        } else {
                                                            ?>
                                                            <a href="javascript:;" class="btn btn-info btn-sm  map_directions_link" data-rel="<?php echo $location_id; ?>"><i class="fa fa-car"></i>
                                                                Driving
                                                                Directions</a>
                                                            <?php
                                                        }

                                                        //echo ' | ';
                                                        if (isset($_REQUEST['page']) && intval($_REQUEST['page']) == 1) {
                                                            ?>
                                                            <a href="<?php echo $protocol . $_SERVER['HTTP_HOST']; ?>/amodules/adverts_map/map_enlarge.php?location_id=<?php echo $location_id; ?>&amp;domain_id=<?php echo $domain_id; ?>"
                                                               target="_self"><i class="fa fa-expand"></i> Enlarge Map</a>
                                                            <?php
                                                        } else {
                                                            ?>
                                                            <a href="javascript:;" class="btn btn-info btn-sm map_enlarge_link" data-rel="<?php echo $location_id; ?>"><i class="fa fa-expand"></i> Enlarge Map</a>
                                                            <?php
                                                        }

                                                        ?>
                                                    </div>
                                                </div>
                                                <?php
                                            }
                                            if($show_postal_address) {
                                                echo $schema_postal_address;
                                            }
                                            ?>
                                            <div class="address-card effect1">
                                                <p class="addr-title">Street Address</p>
                                                <p class="addr-info" translate="no">
                                                <?php
                                                if (trim($data['street']) != "") {
                                                    ?>
                                                    <span <?php echo ($have_microdata) ? 'itemprop="streetAddress"' : ''; ?>>
                                                    <?php
                                                    echo stripslashes($data['street']), ' ', $data['street_no'];
                                                    ?>
                                                    </span>
                                                    <?php
                                                }

                                                if (trim($data['building_name']) != "") {
                                                            echo ", " . stripslashes($data['building_name']);
                                                            ?>
                                                    <?php
                                                }

                                                if (trim($data['floor']) != "") {
                                                            echo ", Floor: " . stripslashes($data['floor']);
                                                }

                                                if (trim($data['flat']) != "") {
                                                            echo ", Flat/Office: " . stripslashes($data['flat']);
                                                }

                                                if (trim($data['city']) != "") {
                                                    ?>

                                                    , <span <?php echo ($have_microdata) ? 'itemprop="addressLocality"' : ''; ?>>
                                                    <?php
                                                        echo stripslashes($data['city']);
                                                        if ($cnt == 1) {
                                                            $meta_loc = trim(stripslashes($data['city']));
                                                        }
                                                    ?>
                                                    </span>
                                                    <?php
                                                }

                                                if (trim($data['area']) != "" && $data['lcode'] == "") {
                                                            echo ", " . stripslashes($data['area']);
                                                            if ($cnt == 1) {
                                                                if ($meta_loc == "") {
                                                                    $meta_loc = trim(stripslashes($data['area']));
                                                                }
                                                            }
                                                }



                                                if (trim($data['district']) != "") {
                                                    ?>
                                                    , <span <?php echo ($have_microdata) ? 'itemprop="addressRegion"' : ''; ?>>
                                                    <?php
                                                    echo stripslashes($data['district']);
                                                    if ($cnt == 1) {
                                                        if ($meta_loc == "") {
                                                            $meta_loc = trim(stripslashes($data['district']));
                                                        } elseif ($meta_loc != trim(stripslashes($data['district']))) {
                                                            $meta_loc .= ", " . trim(stripslashes($data['district']));
                                                        }
                                                    }
                                                    ?>
                                                    </span>
                                                    <?php
                                                    if (trim($data['postalcode']) != "") {
                                                        ?>
                                                        , <span <?php echo ($have_microdata) ? 'itemprop="postalCode"' : ''; ?>><?=stripslashes($data['postalcode']);?></span>
                                                        <?php
                                                    }
                                                }

                                                if (trim($data['country']) != "") {
                                                    ?>
                                                    , <span <?php echo ($have_microdata) ? 'itemprop="addressCountry"' : ''; ?>>Cyprus</span>
                                                    <?php
                                                }

                                                if (trim($data['pobox']) != "") {
                                                    echo "<br>P.O. Box: " . stripslashes($data['pobox']);
                                                }

                                                if (trim($data['pobox_postalcode']) != "") {
                                                    echo "<br>P.O. Box Postal Code: " . stripslashes($data['pobox_postalcode']);
                                                }
                                                ?>
                                                </p>
                                            </div>

                                            <?php
                                            if (trim($data['contact_name']) != "" || trim($data['tel1']) != "") {
                                                ?>
                                                <div class="address-card effect1">
                                                    <p class="addr-title"><?php echo /*$location_title , ' - ', */ 'Contact'; ?></p>
                                                    <div class="addr-info" translate="no">
                                                        <?php

                                                        if (trim($data['contact_name']) != "" && strlen(trim($data['contact_name'])) > 3) {
                                                            echo '<span>';
                                                            echo stripslashes($data['contact_name']);
                                                            if (trim($data['contact_title']) != "") echo '&nbsp;(', stripslashes($data['contact_title']), ')';
                                                            echo '</span>';
                                                        }

                                                        if (isset($data['email']) && trim($data['email']) != "") {
                                                            echo '<br><span> ';
                                                            $loc_emails = array();
                                                            $loc_email = explode("|", $data['email']);
                                                            if (is_array($loc_email) && count($loc_email) > 0) {
                                                                $loc_email = array_map('trim', $loc_email);
                                                                foreach ($loc_email as $l_email) {
                                                                    if ($l_email != "") $loc_emails [] = '<a href="javascript:;" class="mailto" rel="' . str_replace('@', '[ at ]', trim($l_email)) . '">' . str_replace('@', ' [ at ] ', trim($l_email)) . '</a>';
                                                                }
                                                            } else {
                                                                $l_email = trim($data['email']);
                                                                $loc_emails [] = $loc_emails [] = '<a href="javascript:;" class="mailto" rel="' . str_replace('@', '[ at ]', trim($l_email)) . '">' . str_replace('@', ' [ at ] ', trim($l_email)) . '</a>';
                                                            }

                                                            echo implode("; ", $loc_emails);
                                                            echo '</span>';
                                                        }

                                                        if (isset($data['email2']) && trim($data['email2']) != "") {
                                                            echo '<br><span> ';
                                                            $loc_emails = array();
                                                            $loc_email = explode("|", $data['email2']);
                                                            if (is_array($loc_email) && count($loc_email) > 0) {
                                                                $loc_email = array_map('trim', $loc_email);
                                                                foreach ($loc_email as $l_email) {
                                                                    if ($l_email != "") $loc_emails [] = '<a href="javascript:;" class="mailto" rel="' . str_replace('@', '[ at ]', trim($l_email)) . '">' . str_replace('@', ' [ at ] ', trim($l_email)) . '</a>';
                                                                }
                                                            } else {
                                                                $l_email = trim($data['email2']);
                                                                $loc_emails [] = $loc_emails [] = '<a href="javascript:;" class="mailto" rel="' . str_replace('@', '[ at ]', trim($l_email)) . '">' . str_replace('@', ' [ at ] ', trim($l_email)) . '</a>';
                                                            }

                                                            echo implode("; ", $loc_emails);
                                                            echo '</span>';
                                                        }

                                                        if (trim($data['mobile1']) != "" || trim($data['mobile2']) != "") {
                                                            echo '<br><span><i class="fa fa-phone fa-fw" aria-label="Mobile Phone"></i> ';
                                                            ?>
                                                            <span <?php echo ($have_microdata) ? 'itemprop="telephone"' : ''; ?>>
                                                            <?php
                                                            if ($data['mobile1'] != "") {
                                                                echo '(+357) ' . number_format($data['mobile1'], null, null, ' ');
                                                                if ($data['mobile2'] != "") echo '; ' . '(+357) ' . number_format($data['mobile2'], null, null, ' ');
                                                            } else {
                                                                if ($data['mobile2'] != "") echo '(+357) ' . number_format($data['mobile2'], null, null, ' ');
                                                            }
                                                            echo '</span>';
                                                            echo '</span>';

                                                        }

                                                        if (trim($data['tel1']) != "" || trim($data['tel2']) != "") {
                                                            echo '<br><span><i class="fa fa-phone fa-fw" aria-label="Landline Phone"></i> ';
                                                            ?>
                                                            <span <?php echo ($have_microdata) ? 'itemprop="telephone"' : ''; ?>>
                                                            <?php
                                                            if ($data['tel1'] != "") {
                                                                echo '(+357) ' . number_format($data['tel1'], null, null, ' ');
                                                                if ($data['tel2'] != "") echo '; ' . '(+357) ' . number_format($data['tel2'], null, null, ' ');
                                                            } else {
                                                                if ($data['tel2'] != "") echo '(+357) ' . number_format($data['tel2'], null, null, ' ');
                                                            }
                                                            ?>
                                                            </span>
                                                            <?php
                                                            echo '</span>';
                                                        }

                                                        if (trim($data['fax']) != "") {
                                                            echo '<br><span><i class="fa fa-fax fa-fw" aria-label="FAX"></i> ';
                                                            ?>
                                                            <span <?php echo ($have_microdata) ? 'itemprop="faxNumber"' : ''; ?>>
                                                            <?php
                                                            echo '(+357) ' . number_format($data['fax'], null, null, ' ');
                                                            ?>
                                                            </span>
                                                            <?php
                                                            echo '</span>';
                                                        }

                                                        if ($website != "" && $show_website == 1) {
                                                            echo '<br><span><i class="fa fa-globe fa-fw" aria-label="Website Url"></i> ';
                                                            $website = fix_url($website);
                                                            echo $website;

                                                            if ($seo) {
                                                                /*
                                                                if($active == "yes") {
                                                                    if($paying_advert) {
                                                                        if($seo) {
                                                                            ?>
                                                                            <span class="click-link"><?php echo $website;?></span>
                                                                            <?php
                                                                        }
                                                                        else {
                                                                            ?>
                                                                            <a href="click_count.php?link=<?php echo $linePopup["title_tr"];?>&amp;type=www&amp;id=<?php echo $linePopup['advertisment_id'];?>&amp;domain=<?php echo $ultra_domainname;?>&amp;domain_id=<?php echo $domain_id;?>&amp;window=stand&amp;click_from=e" class="click-count" target="_blank" title="<?php echo $website;?>"><?php echo $website;?></a>
                                                                            <?php
                                                                        }
                                                                    }
                                                                    else {
                                                                        echo $website;
                                                                    }
                                                                }
                                                                else {
                                                                    echo $website;
                                                                }
                                                                */
                                                                //echo wordwrap($website, 33, "\n", true);
                                                            } else {
                                                                //echo wordwrap($website, 33, "\n", true);
                                                            }
                                                        }

                                                            if(trim($linePopup['facebook']) !== "") {
                                                                echo '<br><span><i class="fa fa-facebook fa-fw" aria-label="Facebook"></i> <a href="'.trim($linePopup['facebook']).'" title="Connect on Facebook" target="_blank" rel="nofollow noopener">Facebook</a>';
                                                            }

                                                            if(trim($linePopup['twitter']) !== "") {
                                                                echo '<br><span><i class="fa fa-twitter fa-fw" aria-label="Twitter"></i> <a href="'.trim($linePopup['twitter']).'" title="Connect on Twitter" target="_blank" rel="nofollow noopener">Twitter</a>';
                                                            }

                                                            if(trim($linePopup['googleplus']) !== "") {
                                                                echo '<br><span><i class="fa fa-googleplus fa-fw" aria-label="Google+"></i> <a href="'.trim($linePopup['googleplus']).'" title="Connect on Google+" target="_blank" rel="nofollow noopener">Google+</a>';
                                                            }

                                                            if(trim($linePopup['youtube']) !== "") {
                                                                echo '<br><span><i class="fa fa-youtube fa-fw" aria-label="Youtube"></i> <a href="'.trim($linePopup['youtube']).'" title="Connect on Youtube+" target="_blank" rel="nofollow noopener">YouTube</a>';
                                                            }

                                                        ?>
                                                    </div>
                                                </div>
                                                <?php
                                            }
                                            if($show_postal_address) {
                                                echo '</div>';
                                            }
                                            ?>

                                        </div>
                                    </div>
                                    <?php
                                    if($have_microdata) {
                                        // End schema address block
                                        //echo '</div>';
                                    }

                                    //echo ($have_microdata) ? '</div>' : '';
                                    $location_details = ob_get_contents();
                                    ob_end_clean();


                                    ?>
                                    <div class="row">
                                        <div class="col-md-10 col-sm-10">
                                            <?php echo $location_details; ?>
                                        </div>
                                    </div>
                                    <br/>
                                    <?php
                                    $cnt++;
                                }
                            }
                        }


                    }
                    ?>
                </div>
        </article>
        <?php


        if ($meta_loc != "") {
            $meta_params['location'] = $meta_loc;
            $meta_description_temp = str_replace($meta_replacements, $meta_params, $meta_phrase);
            /*
            $meta_description_count = mb_strlen(trim($meta_description_temp), 'UTF-8');
            if($meta_description_count < 10) {
                $meta['description'] = $meta_description_temp . '. ' . mb_substr(trim(strip_tags($advert_meta_description)), 0, (150 - $meta_description_count));
            }
            else {
                $meta['description'] = $meta_description_temp;
            }
            */

            if ($advert_use_meta == 1 && trim($advert_meta_description) != "") {
                $meta['description'] = $advert_meta_description;
                $meta['keywords'] = $advert_meta_keywords;
            } else {
                $meta['description'] = $meta_description_temp;
            }


        }

        ?>
        <script type="text/javascript">
            var click_count_path = '<?=$click_count_path;?>';
            <?php
            if($category_advert || $have_map) {
                ?>
            var map_gmap = null;
            var myLatlng = null;
            var infoWindow = null;
            var markerArray = [];
            var infowindows = [];
            var category_advert = <?php echo($category_advert) ? 'true' : 'false';?>;
            var have_map = <?php echo($have_map) ? 'true' : 'false';?>;
            var big_map_title = '<?=$linePopup['short_title_en'];?>';
            <?php
        }
        else {
            ?>
            var category_advert = <?php echo($category_advert) ? 'true' : 'false';?>;
            var have_map = <?php echo($have_map) ? 'true' : 'false';?>;
            <?php
        }

        ?>
        </script>
        <?php
    } else {
        $send404 = true;
        require_once(dirname(__FILE__) . "/../404/404.php");
    }
}