function replace_listing_field_tags($listing_id, $tempate_section = '', $utf8HTML = false)
 {
     global $lang;
     if (is_numeric($listing_id)) {
         global $config, $conn, $or_replace_listing_id, $or_replace_listing_owner;
         $or_replace_listing_id = $listing_id;
         require_once $config['basepath'] . '/include/listing.inc.php';
         require_once $config['basepath'] . '/include/vtour.inc.php';
         require_once $config['basepath'] . '/include/misc.inc.php';
         $misc = new misc();
         if ($tempate_section != '') {
             $tsection = true;
         } else {
             $tempate_section = $this->page;
             $tsection = false;
         }
         if ($utf8HTML) {
             //Deal with listing field blocks
             $lf_blocks = array();
             preg_match_all('/{listing_field_([^{}]*?)_block}/', $tempate_section, $lf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($lf_blocks) > 1) {
                 foreach ($lf_blocks[1] as $block) {
                     require_once $config['basepath'] . '/include/listing.inc.php';
                     $value = listing_pages::renderSingleListingItem($or_replace_listing_id, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_field_' . $block . '_block}(.*?){\\/listing_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'caption\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'value\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'rawvalue\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return htmlentities(utf8_encode(listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1])), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::get_title($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_title}', $value, $tempate_section);
             $value = listing_pages::get_title($listing_id);
             if ($config["controlpanel_mbstring_enabled"] == 1) {
                 if (mb_detect_encoding($value) != 'UTF-8') {
                     $value = utf8_encode($value);
                 }
             }
             $tempate_section = str_replace('{rss_listing_title}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgent($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_name}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentFirstName($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_first_name}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentLastName($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_last_name}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentLink($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_link}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::get_pclass($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_pclass}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getAgentListingsLink($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_listings}', $value, $tempate_section);
             $value = htmlentities(utf8_encode(listing_pages::getListingAgentID($listing_id)), ENT_QUOTES, 'UTF-8');
             $tempate_section = str_replace('{listing_agent_id}', $value, $tempate_section);
             // Get listing owner
             $owner_sql = 'SELECT userdb_id FROM ' . $config['table_prefix'] . 'listingsdb WHERE (listingsdb_id = ' . $or_replace_listing_id . ')';
             $recordSet = $conn->execute($owner_sql);
             $or_replace_listing_owner = $recordSet->fields['userdb_id'];
             //New listing_agent_field_****_block tag handler for 2.4.1
             $laf_blocks = array();
             preg_match_all('/{listing_agent_field_([^{}]*?)_block}/', $tempate_section, $laf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($laf_blocks) > 1) {
                 foreach ($laf_blocks[1] as $block) {
                     $value = user::renderSingleListingItem($or_replace_listing_owner, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_agent_field_' . $block . '_block}(.*?){\\/listing_agent_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_agent_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_agent_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Replace listing_agent tags
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'caption\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'value\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'rawvalue\')), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return htmlentities(utf8_encode(user::renderSingleListingItem($or_replace_listing_owner, $matches[1])), ENT_QUOTES, \'UTF-8\');'), $tempate_section);
         } else {
             //Deal with listing field blocks
             $lf_blocks = array();
             preg_match_all('/{listing_field_([^{}]*?)_block}/', $tempate_section, $lf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($lf_blocks) > 1) {
                 foreach ($lf_blocks[1] as $block) {
                     require_once $config['basepath'] . '/include/listing.inc.php';
                     $value = listing_pages::renderSingleListingItem($or_replace_listing_id, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_field_' . $block . '_block}(.*?){\\/listing_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'caption\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'value\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1],\'rawvalue\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_id,$lang;require_once($config[\'basepath\'].\'/include/listing.inc.php\'); return listing_pages::renderSingleListingItem($or_replace_listing_id, $matches[1]);'), $tempate_section);
             $value = listing_pages::get_title($listing_id);
             $tempate_section = str_replace('{listing_title}', $value, $tempate_section);
             $value = listing_pages::getListingAgent($listing_id);
             $tempate_section = str_replace('{listing_agent_name}', $value, $tempate_section);
             $value = listing_pages::getListingAgentFirstName($listing_id);
             $tempate_section = str_replace('{listing_agent_first_name}', $value, $tempate_section);
             $value = listing_pages::getListingAgentLastName($listing_id);
             $tempate_section = str_replace('{listing_agent_last_name}', $value, $tempate_section);
             $value = listing_pages::getListingAgentLink($listing_id);
             $tempate_section = str_replace('{listing_agent_link}', $value, $tempate_section);
             $value = listing_pages::get_pclass($listing_id);
             $tempate_section = str_replace('{listing_pclass}', $value, $tempate_section);
             $value = listing_pages::getAgentListingsLink($listing_id);
             $tempate_section = str_replace('{listing_agent_listings}', $value, $tempate_section);
             $value = listing_pages::getListingAgentID($listing_id);
             $tempate_section = str_replace('{listing_agent_id}', $value, $tempate_section);
             // Get listing owner
             $owner_sql = 'SELECT userdb_id FROM ' . $config['table_prefix'] . 'listingsdb WHERE (listingsdb_id = ' . $or_replace_listing_id . ')';
             $recordSet = $conn->execute($owner_sql);
             $or_replace_listing_owner = $recordSet->fields['userdb_id'];
             $laf_blocks = array();
             preg_match_all('/{listing_agent_field_([^{}]*?)_block}/', $tempate_section, $laf_blocks);
             require_once $config['basepath'] . '/include/user.inc.php';
             global $or_replace_listing_owner;
             if (count($laf_blocks) > 1) {
                 foreach ($laf_blocks[1] as $block) {
                     $value = user::renderSingleListingItem($or_replace_listing_owner, $block, 'rawvalue');
                     if ($value == '') {
                         $tempate_section = preg_replace('/{listing_agent_field_' . $block . '_block}(.*?){\\/listing_agent_field_' . $block . '_block}/is', '', $tempate_section);
                     } else {
                         $tempate_section = str_replace('{listing_agent_field_' . $block . '_block}', '', $tempate_section);
                         $tempate_section = str_replace('{/listing_agent_field_' . $block . '_block}', '', $tempate_section);
                     }
                 }
             }
             // Replace listing_agent tags
             // Handle Caption Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_caption}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'caption\');'), $tempate_section);
             // Hanle Value Only
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_value}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'value\');'), $tempate_section);
             // Handle Raw Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)_rawvalue}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1],\'rawvalue\');'), $tempate_section);
             // Handle Both Caption and Value
             $tempate_section = preg_replace_callback('/{listing_agent_field_([^{}]*?)}/', create_function('$matches', 'global $config,$or_replace_listing_owner,$lang;require_once($config[\'basepath\'].\'/include/user.inc.php\'); return user::renderSingleListingItem($or_replace_listing_owner, $matches[1]);'), $tempate_section);
         }
         // Listing Images
         $sql2 = "SELECT listingsdb_title FROM " . $config['table_prefix'] . "listingsdb WHERE listingsdb_id = {$listing_id}";
         $recordSet2 = $conn->Execute($sql2);
         if (!$recordSet2) {
             $misc->log_error($sql2);
         }
         $Title = $misc->make_db_unsafe($recordSet2->fields['listingsdb_title']);
         if ($config['url_style'] == '1') {
             $url = '<a href="index.php?action=listingview&amp;listingID=' . $listing_id . '">';
             $fullurl = '<a href="' . $config["baseurl"] . '/index.php?action=listingview&amp;listingID=' . $listing_id . '">';
             // Listing Link
             $tempate_section = str_replace('{link_to_listing}', 'index.php?action=listingview&amp;listingID=' . $listing_id, $tempate_section);
             $tempate_section = str_replace('{fulllink_to_listing}', $config['baseurl'] . '/index.php?action=listingview&amp;listingID=' . $listing_id, $tempate_section);
         } else {
             $url_title = str_replace("/", "", $Title);
             $url_title = strtolower(str_replace(" ", $config['seo_url_seperator'], $url_title));
             $url = '<a href="listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html">';
             $fullurl = '<a href="' . $config["baseurl"] . '/listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html">';
             // Listing Link
             $tempate_section = str_replace('{link_to_listing}', 'listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html', $tempate_section);
             $tempate_section = str_replace('{fulllink_to_listing}', '' . $config["baseurl"] . '/listing-' . misc::urlencode_to_sef($url_title) . '-' . $listing_id . '.html', $tempate_section);
         }
         // grab the listing's image
         $sql2 = "SELECT listingsimages_id, listingsimages_caption, listingsimages_thumb_file_name, listingsimages_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE listingsdb_id = {$listing_id} ORDER BY listingsimages_rank";
         $recordSet2 = $conn->Execute($sql2);
         if (!$recordSet2) {
             $misc->log_error($sql2);
         }
         $num_images = $recordSet2->RecordCount();
         if ($num_images == 0) {
             if ($config['show_no_photo'] == 1) {
                 $listing_image = $url . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                 $listing_image_full = $fullurl . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                 if ($_GET['action'] == 'listingview') {
                     $listing_image = '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" />';
                     $listing_image_full = '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" />';
                 }
                 $tempate_section = str_replace('{raw_image_thumb_1}', $config['baseurl'] . '/images/nophoto.gif', $tempate_section);
             } else {
                 $listing_image = '';
                 $tempate_section = str_replace('{raw_image_thumb_1}', '', $tempate_section);
             }
             $tempate_section = str_replace('{image_thumb_1}', $listing_image, $tempate_section);
             $tempate_section = str_replace('{image_thumb_fullurl_1}', $listing_image, $tempate_section);
         }
         $x = 1;
         while (!$recordSet2->EOF) {
             //if we're already on the listing then make the urls goto the view image
             $listingsimages_id = $misc->make_db_unsafe($recordSet2->fields['listingsimages_id']);
             $image_caption = $misc->make_db_unsafe($recordSet2->fields['listingsimages_caption']);
             $thumb_file_name = $misc->make_db_unsafe($recordSet2->fields['listingsimages_thumb_file_name']);
             $full_file_name = $misc->make_db_unsafe($recordSet2->fields['listingsimages_file_name']);
             if ($_GET['action'] == 'listingview') {
                 if ($config['url_style'] == '1') {
                     $url = '<a href="index.php?action=view_listing_image&amp;image_id=' . $listingsimages_id . '">';
                     $fullurl = '<a href="' . $config["baseurl"] . '/index.php?action=view_listing_image&amp;image_id=' . $listingsimages_id . '">';
                 } else {
                     $url = '<a href="listing_image_' . $listingsimages_id . '.html">';
                     $fullurl = '<a href="' . $config["baseurl"] . '/listing_image_' . $listingsimages_id . '.html">';
                 }
             }
             if ($thumb_file_name != "" && file_exists("{$config['listings_upload_path']}/{$thumb_file_name}")) {
                 // Full Image Sizes
                 $imagedata = GetImageSize("{$config['listings_upload_path']}/{$full_file_name}");
                 $imagewidth = $imagedata[0];
                 $imageheight = $imagedata[1];
                 $max_width = $config['main_image_width'];
                 $max_height = $config['main_image_height'];
                 $resize_by = $config['resize_by'];
                 $shrinkage = 1;
                 if ($max_width == $imagewidth || $max_height == $imageheight) {
                     $display_width = $imagewidth;
                     $display_height = $imageheight;
                 } else {
                     if ($resize_by == 'width') {
                         $shrinkage = $imagewidth / $max_width;
                         $display_width = $max_width;
                         $display_height = round($imageheight / $shrinkage);
                     } elseif ($resize_by == 'height') {
                         $shrinkage = $imageheight / $max_height;
                         $display_height = $max_height;
                         $display_width = round($imagewidth / $shrinkage);
                     } elseif ($resize_by == 'both') {
                         $display_width = $max_width;
                         $display_height = $max_height;
                     } elseif ($resize_by == 'bestfit') {
                         $shrinkage_width = $imagewidth / $max_width;
                         $shrinkage_height = $imageheight / $max_height;
                         $shrinkage = max($shrinkage_width, $shrinkage_height);
                         $display_height = round($imageheight / $shrinkage);
                         $display_width = round($imagewidth / $shrinkage);
                     }
                 }
                 // Thumbnail Image Sizes
                 $thumb_imagedata = GetImageSize("{$config['listings_upload_path']}/{$thumb_file_name}");
                 $thumb_imagewidth = $thumb_imagedata[0];
                 $thumb_imageheight = $thumb_imagedata[1];
                 $thumb_max_width = $config['thumbnail_width'];
                 $thumb_max_height = $config['thumbnail_height'];
                 $resize_thumb_by = $config['resize_thumb_by'];
                 $shrinkage = 1;
                 if ($thumb_max_width == $thumb_imagewidth || $thumb_max_height == $thumb_imageheight) {
                     $thumb_displaywidth = $thumb_imagewidth;
                     $thumb_displayheight = $thumb_imageheight;
                 } else {
                     if ($resize_thumb_by == 'width') {
                         $shrinkage = $thumb_imagewidth / $thumb_max_width;
                         $thumb_displaywidth = $thumb_max_width;
                         $thumb_displayheight = round($thumb_imageheight / $shrinkage);
                     } elseif ($resize_thumb_by == 'height') {
                         $shrinkage = $thumb_imageheight / $thumb_max_height;
                         $thumb_displayheight = $thumb_max_height;
                         $thumb_displaywidth = round($thumb_imagewidth / $shrinkage);
                     } elseif ($resize_thumb_by == 'both') {
                         $thumb_displayheight = $thumb_max_height;
                         $thumb_displaywidth = $thumb_max_width;
                     }
                 }
                 $listing_image = $url . '<img src="' . $config['listings_view_images_path'] . '/' . $thumb_file_name . '" height="' . $thumb_displayheight . '" width="' . $thumb_displaywidth . '" alt="' . $image_caption . '" /></a>';
                 $listing_image_full = $url . '<img src="' . $config['listings_view_images_path'] . '/' . $full_file_name . '" height="' . $display_height . '" width="' . $display_width . '" alt="' . $image_caption . '" /></a>';
                 $listing_image_fullurl = $fullurl . '<img src="' . $config['listings_view_images_path'] . '/' . $thumb_file_name . '" height="' . $thumb_displayheight . '" width="' . $thumb_displaywidth . '" alt="' . $image_caption . '" /></a>';
                 $listing_image_full_fullurl = $fullurl . '<img src="' . $config['listings_view_images_path'] . '/' . $full_file_name . '" height="' . $display_height . '" width="' . $display_width . '" alt="' . $image_caption . '" /></a>';
                 $tempate_section = str_replace('{image_thumb_' . $x . '}', $listing_image, $tempate_section);
                 $tempate_section = str_replace('{raw_image_thumb_' . $x . '}', $config['listings_view_images_path'] . '/' . $thumb_file_name, $tempate_section);
                 $tempate_section = str_replace('{image_thumb_fullurl_' . $x . '}', $listing_image_fullurl, $tempate_section);
                 //Full Image tags
                 $tempate_section = str_replace('{image_full_' . $x . '}', $listing_image_full, $tempate_section);
                 $tempate_section = str_replace('{raw_image_full_' . $x . '}', $config['listings_view_images_path'] . '/' . $full_file_name, $tempate_section);
                 $tempate_section = str_replace('{image_full_fullurl_' . $x . '}', $listing_image_full_fullurl, $tempate_section);
             } else {
                 if ($config['show_no_photo'] == 1) {
                     $listing_image = $url . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                     $listing_image_fullurl = $fullurl . '<img src="' . $config["baseurl"] . '/images/nophoto.gif" alt="' . $lang['no_photo'] . '" /></a>';
                     $tempate_section = str_replace('{raw_image_thumb_' . $x . '}', $config['baseurl'] . '/images/nophoto.gif', $tempate_section);
                 } else {
                     $listing_image = '';
                     $tempate_section = str_replace('{raw_image_thumb_' . $x . '}', '', $tempate_section);
                 }
                 $tempate_section = str_replace('{image_thumb_' . $x . '}', $listing_image, $tempate_section);
                 $tempate_section = str_replace('{image_thumb_fullurl_' . $x . '}', $listing_image_fullurl, $tempate_section);
                 $tempate_section = str_replace('{image_full_' . $x . '}', '', $tempate_section);
                 $tempate_section = str_replace('{raw_image_full_' . $x . '}', '', $tempate_section);
                 $tempate_section = str_replace('{image_full_fullurl_' . $x . '}', '', $tempate_section);
             }
             // We have the image so insert it into the section.
             $x++;
             $recordSet2->MoveNext();
         }
         // end while
         // End Listing Images
         $value = array();
         $value = listing_pages::getListingAgentThumbnail($listing_id);
         $x = 0;
         foreach ($value as $y) {
             $tempate_section = str_replace('{listing_agent_thumbnail_' . $x . '}', $y, $tempate_section);
             $x++;
         }
         $tempate_section = preg_replace('/{listing_agent_thumbnail_([^{}]*?)}/', '', $tempate_section);
         // End of Listing Tag Replacement
         if ($tsection === true) {
             return $tempate_section;
         } else {
             $this->page = $tempate_section;
         }
     }
 }
 function renderNotifyListings($listingIDArray, $search_title, $user_name, $email)
 {
     global $conn, $lang, $config, $db_type, $current_ID;
     //Load the Core Template class and the Misc Class
     require_once $config['basepath'] . '/include/class/template/core.inc.php';
     $page = new page_user();
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     require_once $config['basepath'] . '/include/listing.inc.php';
     $listingclass = new listing_pages();
     //Declare an empty display variable to hold all output from function.
     $display = '';
     //If We have a $current_ID save it
     $old_current_ID = '';
     if ($current_ID != '') {
         $old_current_ID = $current_ID;
     }
     //Load the Notify Listing Template specified in the Site Config
     $page->load_page($config['template_path'] . '/' . $config['notify_listings_template']);
     // Determine if the template uses rows.
     // First item in array is the row conent second item is the number of block per block row
     $notify_template_row = $page->get_template_section_row('notify_listing_block_row');
     if (is_array($notify_template_row)) {
         $row = $notify_template_row[0];
         $col_count = $notify_template_row[1];
         $user_rows = true;
         $x = 1;
         //Create an empty array to hold the row conents
         $new_row_data = array();
     } else {
         $user_rows = false;
     }
     $notify_template_section = '';
     foreach ($listingIDArray as $current_ID) {
         if ($user_rows == true && $x > $col_count) {
             //We are at then end of a row. Save the template section as a new row.
             $new_row_data[] = $page->replace_template_section('notify_listing_block', $notify_template_section, $row);
             //$new_row_data[] = $notify_template_section;
             $notify_template_section = $page->get_template_section('notify_listing_block');
             $x = 1;
         } else {
             $notify_template_section .= $page->get_template_section('notify_listing_block');
         }
         $listing_title = $listingclass->get_title($current_ID);
         if ($config['url_style'] == '1') {
             $notify_url = $config['baseurl'] . '/index.php?action=listingview&amp;listingID=' . $current_ID;
             // #####
         } else {
             $url_title = str_replace("/", "", $listing_title);
             $url_title = strtolower(str_replace(" ", $config['seo_url_seperator'], $url_title));
             $notify_url = $config['baseurl'] . '/listing-' . misc::urlencode_to_sef($url_title) . '-' . $current_ID . '.html';
             // #####
         }
         $notify_template_section = $page->replace_listing_field_tags($current_ID, $notify_template_section);
         $notify_template_section = $page->replace_listing_field_tags($current_ID, $notify_template_section);
         $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_url', $notify_url);
         $notify_template_section = $page->parse_template_section($notify_template_section, 'listingid', $current_ID);
         // Setup Image Tags
         $sql2 = "SELECT listingsimages_thumb_file_name,listingsimages_file_name\n\t\t\t\t\tFROM " . $config['table_prefix'] . "listingsimages\n\t\t\t\t\tWHERE (listingsdb_id = {$current_ID})\n\t\t\t\t\tORDER BY listingsimages_rank";
         $recordSet2 = $conn->SelectLimit($sql2, 1, 0);
         if ($recordSet2 === false) {
             $misc->log_error($sql2);
         }
         if ($recordSet2->RecordCount() > 0) {
             $thumb_file_name = $misc->make_db_unsafe($recordSet2->fields['listingsimages_thumb_file_name']);
             $file_name = $misc->make_db_unsafe($recordSet2->fields['listingsimages_file_name']);
             if ($thumb_file_name != "" && file_exists("{$config['listings_upload_path']}/{$thumb_file_name}")) {
                 // gotta grab the thumbnail image size
                 $imagedata = GetImageSize("{$config['listings_upload_path']}/{$thumb_file_name}");
                 $imagewidth = $imagedata[0];
                 $imageheight = $imagedata[1];
                 $shrinkage = $config['thumbnail_width'] / $imagewidth;
                 $notify_thumb_width = $imagewidth * $shrinkage;
                 $notify_thumb_height = $imageheight * $shrinkage;
                 $notify_thumb_src = $config['listings_view_images_path'] . '/' . $thumb_file_name;
                 // gotta grab the thumbnail image size
                 $imagedata = GetImageSize("{$config['listings_upload_path']}/{$file_name}");
                 $imagewidth = $imagedata[0];
                 $imageheight = $imagedata[1];
                 $notify_width = $imagewidth;
                 $notify_height = $imageheight;
                 $notify_src = $config['listings_view_images_path'] . '/' . $file_name;
             }
         } else {
             if ($config['show_no_photo'] == 1) {
                 $imagedata = GetImageSize($config['basepath'] . "/images/nophoto.gif");
                 $imagewidth = $imagedata[0];
                 $imageheight = $imagedata[1];
                 $shrinkage = $config['thumbnail_width'] / $imagewidth;
                 $notify_thumb_width = $imagewidth * $shrinkage;
                 $notify_thumb_height = $imageheight * $shrinkage;
                 $notify_thumb_src = $config['baseurl'] . '/images/nophoto.gif';
                 $notify_width = $notify_thumb_width;
                 $notify_height = $notify_thumb_height;
                 $notify_src = $config['baseurl'] . '/images/nophoto.gif';
             } else {
                 $notify_thumb_width = '';
                 $notify_thumb_height = '';
                 $notify_thumb_src = '';
                 $notify_width = '';
                 $notify_height = '';
                 $notify_src = '';
             }
         }
         if (!empty($notify_thumb_src)) {
             $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_thumb_src', $notify_thumb_src);
             $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_thumb_height', $notify_thumb_height);
             $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_thumb_width', $notify_thumb_width);
             $notify_template_section = $page->cleanup_template_block('notify_img', $notify_template_section);
         } else {
             $notify_template_section = $page->remove_template_block('notify_img', $notify_template_section);
         }
         if (!empty($notify_src)) {
             $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_large_src', $notify_src);
             $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_large_height', $notify_height);
             $notify_template_section = $page->parse_template_section($notify_template_section, 'notify_large_width', $notify_width);
             $notify_template_section = $page->cleanup_template_block('notify_img_large', $notify_template_section);
         } else {
             $notify_template_section = $page->remove_template_block('notify_img_large', $notify_template_section);
         }
         if ($user_rows == true) {
             $x++;
         }
     }
     if ($user_rows == true) {
         $notify_template_section = $page->cleanup_template_block('notify_listing', $notify_template_section);
         $new_row_data[] = $page->replace_template_section('notify_listing_block', $notify_template_section, $row);
         $replace_row = '';
         foreach ($new_row_data as $rows) {
             $replace_row .= $rows;
         }
         $page->replace_template_section_row('notify_listing_block_row', $replace_row);
     } else {
         $page->replace_template_section('notify_listing_block', $notify_template_section);
     }
     $page->replace_permission_tags();
     $page->replace_urls();
     $page->auto_replace_tags();
     $page->replace_lang_template_tags();
     $display .= $page->return_page();
     $current_ID = '';
     if ($old_current_ID != '') {
         $current_ID = $old_current_ID;
     }
     return $display;
 }
Beispiel #3
0
 function view_image($type)
 {
     global $conn, $config, $lang;
     require_once $config['basepath'] . '/include/misc.inc.php';
     require_once $config['basepath'] . '/include/listing.inc.php';
     $misc = new misc();
     $display = '';
     if (!isset($_GET['image_id'])) {
         return $lang['image_not_found'];
     }
     $sql_imageID = $misc->make_db_safe($_GET['image_id']);
     if ($type == "listing") {
         // get the image data
         $sql = "SELECT listingsimages_caption, listingsimages_file_name, listingsimages_description, listingsdb_id FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsimages_id = {$sql_imageID})";
         $recordSet = $conn->Execute($sql);
         if ($recordSet === false) {
             $misc->log_error($sql);
         }
         while (!$recordSet->EOF) {
             $caption = $misc->make_db_unsafe($recordSet->fields['listingsimages_caption']);
             $file_name = $misc->make_db_unsafe($recordSet->fields['listingsimages_file_name']);
             $description = $misc->make_db_unsafe($recordSet->fields['listingsimages_description']);
             $listing_id = $misc->make_db_unsafe($recordSet->fields['listingsdb_id']);
             $recordSet->MoveNext();
         }
         $display .= '<div class="view_image">';
         $display .= '<span class="image_caption">';
         if ($caption != "") {
             $display .= "{$caption} - ";
         }
         //SEO Friendly Links
         $Title = listing_pages::get_title($listing_id);
         if ($config['url_style'] == '1') {
             $url = '<a href="index.php?action=listingview&amp;listingID=' . $listing_id . '">';
         } else {
             $url_title = str_replace("/", "", $Title);
             $url_title = strtolower(str_replace(" ", $config['seo_url_seperator'], $url_title));
             $url = '<a href="listing-' . urlencode($url_title) . '-' . $listing_id . '.html">';
         }
         $display .= $url . $lang['return_to_listing'] . '</a></span><br />';
         $display .= '<img src="' . $config['listings_view_images_path'] . '/' . $file_name . '" alt="' . $caption . '"  />';
         $display .= '<br />';
         $display .= $description;
         $display .= '</div>';
     } elseif ($type == "userimage") {
         // get the image data
         $sql = "SELECT userimages_caption, userimages_file_name, userimages_description, userdb_id FROM " . $config['table_prefix'] . "userimages WHERE (userimages_id = {$sql_imageID})";
         $recordSet = $conn->Execute($sql);
         if ($recordSet === false) {
             $misc->log_error($sql);
         }
         while (!$recordSet->EOF) {
             $caption = $misc->make_db_unsafe($recordSet->fields['userimages_caption']);
             $file_name = $misc->make_db_unsafe($recordSet->fields['userimages_file_name']);
             $description = $misc->make_db_unsafe($recordSet->fields['userimages_description']);
             $user_id = $recordSet->fields['userdb_id'];
             $recordSet->MoveNext();
         }
         $display .= '<table class="form_" align="center">';
         $display .= '<tr>';
         $display .= '	<td class="row_main">';
         $display .= '		<h3>';
         if ($caption != "") {
             $display .= "{$caption} - ";
         }
         $display .= '<a href="index.php?action=view_user&amp;user='******'">' . $lang['return_to_user'] . '</a></h3>';
         $display .= '		<center>';
         $display .= '		<img src="' . $config['user_view_images_path'] . '/' . $file_name . '" alt="' . $caption . '" border="1">';
         $display .= '		</center>';
         $display .= '		<br />';
         $display .= $description;
         $display .= '	</td>';
         $display .= '</tr>';
         $display .= '</table>';
     }
     // end if ($type == "listing")
     return $display;
 }
 /**
  * maps::create_map_link()
  * This is the function to call to show a map link. It should be called from the listing detail page, or any page where $_GET['listingID'] is set.
  * This function then calls the appropriate make_mapname function as specified in the configuration.
  *
  * @see maps::make_mapquest()
  * @see maps::make_yahoo_us()
  * @return string Return the URL for the map as long as the required fields are filled out, if not it returns a empty string.
  */
 function create_map_link($url_only = 'no')
 {
     global $conn, $config;
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     // Map Type
     // Get Address, City, State, Zip
     // Create Blank Variables
     $display = '';
     $address = '';
     $city = '';
     $state = '';
     $zip = '';
     // Get Listing ID
     $sql_listingID = $misc->make_db_safe($_GET['listingID']);
     $listing_title = urlencode(listing_pages::get_title($_GET['listingID']));
     // get address
     $sql_address_field = $misc->make_db_safe($config['map_address']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_address_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $address = urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     // Add address fields 2 & 3
     $sql_address_field = $misc->make_db_safe($config['map_address2']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_address_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $address .= ' ' . urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     $sql_address_field = $misc->make_db_safe($config['map_address3']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_address_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $address .= ' ' . urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     $sql_address_field = $misc->make_db_safe($config['map_address4']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_address_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $address .= ' ' . urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     // get city
     $sql_city_field = $misc->make_db_safe($config['map_city']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_city_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $city = urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     // get state
     $sql_state_field = $misc->make_db_safe($config['map_state']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_state_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $state = urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     // get zip
     $sql_zip_field = $misc->make_db_safe($config['map_zip']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_zip_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $zip = urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     // get zip
     $sql_country_field = $misc->make_db_safe($config['map_country']);
     $sql = "SELECT listingsdbelements_field_value, listingsformelements_field_type, listingsformelements_field_caption FROM " . $config['table_prefix'] . "listingsdbelements, " . $config['table_prefix'] . "listingsformelements WHERE ((" . $config['table_prefix'] . "listingsdbelements.listingsdb_id = {$sql_listingID}) AND (listingsformelements_field_name = listingsdbelements_field_name) AND (listingsdbelements_field_name = {$sql_country_field}))";
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     while (!$recordSet->EOF) {
         $country = urlencode($misc->make_db_unsafe($recordSet->fields['listingsdbelements_field_value']));
         $recordSet->MoveNext();
     }
     // end while
     if ($address != '' || $city != '' || $state != '' || $zip != '') {
         $map_type = 'make_' . $config['map_type'];
         $pos = strpos($map_type, 'mapquest');
         $pos2 = strpos($map_type, 'multimap');
         $pos3 = strpos($map_type, 'global_');
         if ($pos3 !== false) {
             if ($pos !== false) {
                 $display = maps::make_mapquest($country, $address, $city, $state, $zip, $listing_title, $url_only);
             } elseif ($pos2 !== false) {
                 $display = maps::make_multimap($country, $address, $city, $state, $zip, $listing_title, $url_only);
             }
         } elseif ($pos !== false) {
             $country = substr($map_type, -2);
             $display = maps::make_mapquest($country, $address, $city, $state, $zip, $listing_title, $url_only);
         } elseif ($pos2 !== false) {
             $country = substr($map_type, -2);
             $display = maps::make_multimap($country, $address, $city, $state, $zip, $listing_title, $url_only);
         } else {
             $display = maps::$map_type($address, $city, $state, $zip, $listing_title, $url_only);
         }
     }
     return $display;
 }