Пример #1
0
function sb_listing_func()
{
    global $sb_config, $user_email, $user_identity, $current_user, $wp_query;
    include_once 'utility_functions.php';
    $boat_id = '';
    //var_dump($wp_query->query_vars);
    if (array_key_exists('boat_id', $_GET)) {
        $boat_id = $_GET['boat_id'];
    } else {
        $boat_id = get_query_var('boat_id');
        //used if there's a rewrite in operation
    }
    if (array_key_exists('server', $_GET) and $_GET['server'] != '') {
        $sb_config['server_address'] = urldecode($_GET['server']);
    } elseif (get_query_var('server_address', 'none') != 'none') {
        $sb_config['server_address'] = get_query_var('server_address');
        //used if there's a rewrite in operation
    }
    $sb_config['video_link'] = '<div class="sb_clean_thumb" style="display: none;">
		<a href="http://www.youtube.com/watch?v=%1$s?rel=0&wmode=opaque&modestbranding=1&showinfo=0&theme=light" rel="sb_prettyPhoto[all]" title="Video: %2$s" style="text-decoration: none;">
			<div class="sb_clean_vt_holder">
				<span>&#9654;</span>
			</div>
		</a>
	</div>';
    //configure tracking, if required
    $tracking_code = '';
    if (is_user_logged_in() and array_key_exists('sb_tracking', $sb_config)) {
        $tracking_code = "&track=true&a1=" . urlencode($user_email) . "&a2=" . urlencode($current_user->display_name);
    }
    $site_id = explode(".", $sb_config['server_address']);
    $site_id = $site_id[0];
    $site_id = explode("/", $site_id);
    $site_id = end($site_id);
    $xml_file = $sb_config['server_address'] . "/system/wp_plugin/boat.php?boat_id={$boat_id}";
    $xml = sb_load_xml($xml_file);
    if ($xml !== FALSE) {
        //check if we're using a server other than the default, and substitute in the proper config node if required
        $sb_temp_config = get_option('sb_plugin_options');
        if ($sb_config['server_address'] != $sb_temp_config['server_address']) {
            $xml_file = $sb_temp_config['server_address'] . "/system/wp_plugin/boat.php?boat_id=0";
            $xml2 = sb_load_xml($xml_file);
            $domToChange = dom_import_simplexml($xml->config);
            $domReplace = dom_import_simplexml($xml2->config);
            $nodeImport = $domToChange->ownerDocument->importNode($domReplace, TRUE);
            $domToChange->parentNode->replaceChild($nodeImport, $domToChange);
        }
        //--------------------------------------------
        // Format price
        //--------------------------------------------
        //load exchange rates into sb_config
        foreach ($xml->currencies->currency as $c) {
            $sb_config['currencies'][strval($c->currency)] = array('rate' => floatval($c->rate), 'symbol' => strval($c->symbol), 'name' => strval($c->name), 'suffix' => strval($c->suffix));
        }
        $currency = $xml->boat->currency;
        $curr_symbol = $xml->boat->symbol;
        $value = floatval($xml->boat->asking_price);
        //Tax label
        $vat_paid = $xml->boat->vat_included;
        if ($vat_paid == '1') {
            $vat_message = $xml->config->tax_label . " " . $xml->config->tax_paid_label;
        } else {
            $vat_message = $xml->config->tax_label . " " . $xml->config->tax_not_paid_label;
        }
        if ($sb_config['hide_tax_label'] == 'on') {
            $vat_message = '';
        }
        if ($xml->boat->suffix == 1) {
            $price = number_format($value, 0) . '&nbsp;' . $curr_symbol . ' ' . $vat_message;
        } else {
            $price = $curr_symbol . number_format($value, 0) . ' ' . $vat_message;
        }
        //add currency conversion if not in primary currency
        $currency_conversion = currency_conversion($value, $currency);
        //--------------------------------------------
        // Format provisional message
        //--------------------------------------------
        $prov = $xml->boat->approved;
        $prov_message = '';
        if ($prov != 'true') {
            $prov_message = '<p><em>' . $xml->config->provisional_listing_disclaimer . '</em></p>';
        }
        //--------------------------------------------
        // Compile specification categories
        //--------------------------------------------
        $cats = '';
        $i = '';
        $j = '';
        $k = '';
        foreach ($xml->boat->specifications->categories->category as $category) {
            $e = "<hr/><h3>" . $category->name . "</h3><hr/><p>";
            foreach ($category->item as $item) {
                $e .= $item->name;
                $note = $item->note;
                //note already includes units in XML feed
                if ($note != '') {
                    $e .= ": " . $note;
                }
                $e .= "<br/>";
            }
            $e = substr($e, 0, -5) . "</p>";
            if (strlen($i) > strlen($j) and strlen($j) >= strlen($k)) {
                $k .= $e;
            } elseif (strlen($i) > strlen($k) and strlen($k) >= strlen($j)) {
                $j .= $e;
            } else {
                $i .= $e;
            }
        }
        $cats = "<div class='smartbroker_section smartbroker_group'>\r\n\t\t\t\t\t<div class='smartbroker_col smartbroker_span_1_of_3'>{$i}</div>\r\n\t\t\t\t\t<div class='smartbroker_col smartbroker_span_1_of_3'>{$j}</div>\r\n\t\t\t\t\t<div class='smartbroker_col smartbroker_span_1_of_3'>{$k}</div>\r\n\t\t\t\t</div>";
        //--------------------------------------------
        // Compile media
        //--------------------------------------------
        $m = "<div id='sb_clean_thumb_window'>";
        foreach ($xml->boat->media->media as $media) {
            if ($media['type'] == 'photo') {
                $m .= build_photo($media->link, $media->path, $media->description, $boat_id, $xml);
            } elseif ($media['type'] == 'video') {
                $m .= sprintf($sb_config['video_link'], $media->video_id, $media->description);
            }
        }
        $m .= "</div>";
        //count photos and videos
        $photos = $xml->xpath('//*[@type="photo"]');
        $num_photos = count($photos);
        $videos = $xml->xpath('//*[@type="video"]');
        $num_videos = count($videos);
        if ($num_photos > 8 or $num_videos > 0) {
            $m .= "<a id='sb_view_all_link' href='#' style='text-align: right; display: block;'>+ ";
            if ($num_photos - 9 == 1) {
                $mes .= " 1 more photo";
            }
            if ($num_photos - 9 > 1) {
                $mes .= $num_photos - 9 . " more photos";
            }
            if ($num_videos == 1) {
                if ($mes != '') {
                    $mes .= ' and';
                }
                $mes .= " 1 video";
            }
            if ($num_videos > 1) {
                if ($mes != '') {
                    $mes .= ' and';
                }
                $mes .= " {$num_videos} videos";
            }
            $m .= $mes . "</a>";
        }
        //--------------------------------------------
        // Sort the find out more div
        //--------------------------------------------
        include_once 'find_out_more.php';
        $brokers_notes = nl2br($xml->boat->brokers_notes);
        if ($brokers_notes == '') {
            $brokers_notes = "<em>" . __("(There are no broker's notes available for this boat)", 'smartbroker') . "</em>";
        }
        //--------------------------------------------
        // Status label (if required)
        //--------------------------------------------
        $label = '';
        if ($xml->boat->add_label == 1) {
            $label = $xml->boat->status_text . '<br/>';
        }
        //--------------------------------------------
        // Catch widgets into variables
        //--------------------------------------------
        ob_start();
        dynamic_sidebar('sb_listing_under_photos');
        $wd1 = ob_get_contents();
        ob_end_clean();
        //--------------------------------------------
        // Build image & key facts blocks
        //--------------------------------------------
        $image_link = $sb_config['server_address'] . "/images/boats/{$boat_id}/large/" . $xml->boat->primary_photo . ".jpg";
        $image = "<div id='sb_primary_image'>\r\n\t\t\t\t<a href='{$image_link}' rel='sb_prettyPhoto[all]' title=''>\r\n\t\t\t\t<img src='{$image_link}' title='' alt='" . $xml->boats->model . "'/>\r\n\t\t\t\t</a>\t \r\n\t\t\t</div>\r\n\t\t\t<div class='sb_no_print'>{$m}</div>{$wd1}";
        //key facts
        $kf = "<div class='sb_wide_only'><h1 style='clear: left;'><span id='sb_boat_builder_and_model'>" . $xml->boat->builder . " " . $xml->boat->model . "</span>" . $admin_link . "</h1></div>\r\n\t\t<h2 style='clear: left;'><span class='sb_price_message'>{$label}" . $price . "\r\n\t\t<br /><small>" . $currency_conversion . "</small></span></h2>\r\n\t\t<p><span class='sb_year_message'>" . __('Built', 'smartbroker') . ': ' . $xml->boat->year . "</span><span class='sb_lying_message'><br/>" . __('Currently lying', 'smartbroker') . ': ' . $xml->boat->region . ", " . $xml->boat->country_name . "</span></p>";
        if ($xml->boat->approved == 'false') {
            $kf .= $prov_message;
        }
        //--------------------------------------------
        // Data required by javascript
        //--------------------------------------------
        $a = "<div style='display: none;' id='server_address_address'>" . $sb_config['server_address'] . "</div>";
        $a .= "<div style='display: none;' id='sb_listing_page'>" . $sb_config['listing_page'] . "</div>";
        //--------------------------------------------
        // Compile main layout
        //--------------------------------------------
        $a .= "\r\n\t\t<div class='sb_wrapper sb_theme_clean'>\r\n\t\t<div class='sb_narrow_only'><h1 style='clear: left;'><span id='sb_boat_builder_and_model'>" . $xml->boat->builder . " " . $xml->boat->model . "</span></h1></div>\r\n\t\t<div>\r\n\t\t\t<div id='sb_clean_images'>\r\n\t\t\t\t{$image}\r\n\t\t\t</div>\r\n\t\t\t{$kf}\r\n\t\t\t<div class='sb_no_print'>\r\n\t\t\t\t<button onclick=\"location.href='#sb_find_out_more';\" style='position: relative !important;' \\>\r\n\t\t\t\t\t" . __('Contact us about this boat', 'smartbroker') . "\r\n\t\t\t\t</button>\r\n\t\t\t\t<br/><br/>\r\n\t\t\t</div>\r\n\t\t\t<hr style='clear: left;'/>\r\n\t\t\t<p><br/>{$brokers_notes}</p>\r\n\t\t</div>\r\n\t\t{$cats}\r\n\t\t<hr/><div class='sb_no_print'><a name='sb_find_out_more'></a><h3>" . __('Find out more', 'smartbroker') . "</h3>{$find_out_more}</div>\r\n\t\t<hr /><p><small>" . $xml->config->disclaimer . "</small></p>\r\n\t\t</div> <!--end sb_wrapper -->";
        return $a;
    }
}
Пример #2
0
function search_result_item($boat)
{
    global $sb_config;
    $desc = $boat->builder . " " . $boat->model;
    if (isset($boat->vat_message)) {
        $vat_message = $boat->vat_message;
    } else {
        if ($boat->vat_paid == '1') {
            $vat_message = "VAT " . __('paid', 'smartbroker');
        } else {
            $vat_message = "VAT " . __('not paid', 'smartbroker');
        }
    }
    $status_message = '';
    $featured = false;
    if ($boat->status != '' and $boat->add_label == '1') {
        $status_message = " <span class='sb_status_message sb_status_" . strtolower(str_replace(' ', '_', $boat->status)) . "'>" . $boat->status . '</span>';
    }
    if ($boat->status == 'Featured') {
        $featured = true;
    }
    if (!array_key_exists('listing_default_tab', $sb_config)) {
        $sb_config['listing_default_tab'] = '';
    }
    if (get_option('permalink_structure')) {
        //use pretty links
        //get subdomain of server address
        $elements = explode('.', $sb_config['server_address']);
        $server_subdomain = substr($elements[0], 7);
        $link = site_url('/boats-for-sale/' . $boat->boat_id . '/' . urlencode($server_subdomain) . '/' . urlencode($desc));
    } else {
        //no pretty links, boo!
        $link = site_url("/?page_id=" . $sb_config['listing_page'] . "&boat_id=" . $boat->boat_id . "&server=" . urlencode($sb_config['server_address']) . '#' . $sb_config['listing_default_tab']);
    }
    $length = round($boat->LOA) . ' ' . $sb_config['units']['LOA'];
    //format currency
    $currency = $boat->currency;
    $curr_symbol = $sb_config['currencies'][strval($currency)]['symbol'];
    $price = number_format(floatval($boat->price));
    $currency_conversion = currency_conversion(floatval($boat->price), $currency);
    if ($currency_conversion != '') {
        $currency_conversion = "<small>{$currency_conversion}</small>";
    }
    if ($sb_config['currencies'][strval($currency)]['suffix']) {
        $price_message = $price . $curr_symbol . ' ' . $currency_conversion . ' ' . $vat_message;
    } else {
        $price_message = $curr_symbol . $price . ' ' . $currency_conversion . ' ' . $vat_message;
    }
    if ($featured) {
        $img_link = $sb_config['server_address'] . "/images/boats/" . $boat->boat_id . '/medium/' . $boat->photo_id . ".jpg";
        $a = "\r\n\t\t\t<div class='sb_listing_item sb_clearfix' style='clear: both; margin-bottom: .2em;'>\r\n\t\t\t\t\r\n\t\t\t\t<a href='{$link}' style='display: block; float: left; margin-right: 1em;' class='sb_img_featured'><img src='{$img_link}' alt='{$desc}' title='{$desc}'></a>\r\n\t\t\t\t<div style='padding-left: .5em; display: block;'>\r\n\t\t\t\t\t<h3 style='clear: right; margin-top: .5em;'><a href='{$link}'>{$desc}</a></h3>\r\n\t\t\t\t\t\r\n\t\t\t\t\t<p>{$length}<span class='sb_year_message'>, " . __('built', 'smartbroker') . " {$boat->year}</span><span class='sb_lying_message'>, " . __('lying', 'smartbroker') . " " . trim($boat->region . ' ' . $boat->country) . "</span><span class='sb_price_message'><br/>{$price_message}</span></p>\r\n\t\t\t\t\t\r\n\t\t\t\t\t<input type='button' value='View boat details' onclick='window.location=\"{$link}\"' style='margin-bottom: .5em;' class='sb_results_button_link_featured'/>\r\n\t\t\t\t</div>\r\n\t\t\t\t\t\r\n\t\t\t</div>";
    } else {
        $img_link = $sb_config['server_address'] . "/images/boats/" . $boat->boat_id . '/medium/' . $boat->photo_id . ".jpg";
        $a = "\r\n\t\t\t<div class='sb_listing_item sb_clearfix' style='clear: both;'>\r\n\t\t\t\t\r\n\t\t\t\t<a href='{$link}' style='display: block; float: left; margin-right: .5em; margin-top: .5em;' class='sb_img_standard'><img src='{$img_link}' alt='{$desc}' title='{$desc}'></a>\r\n\t\t\t\t<div style='display: inline-block;'>\r\n\t\t\t\t<h3 style='clear: right; margin-top: .5em;'><a href='{$link}'>{$desc}</a>{$status_message}</h3>\r\n\t\t\t\t\r\n\t\t\t\t<p>{$length}<span class='sb_year_message'>, " . __('built', 'smartbroker') . " {$boat->year}</span><span class='sb_lying_message'>, " . __('lying', 'smartbroker') . " " . trim($boat->region . ' ' . $boat->country) . "</span><span class='sb_price_message'>, {$price_message}</span></p>\r\n\t\t\t\t<input type='button' value='View boat details' onclick='window.location=\"{$link}\"' style='margin-bottom: .5em;' class='sb_results_button_link_standard'/>\r\n\t\t\t\t</div>\t\r\n\t\t\t</div>";
    }
    return $a;
}