get('Plugins')->run_hook('listing_begin');
$PMDR->loadLanguage(array('public_listing','general_locations'));
$listing = $PMDR->get('Listings')->getJoinedUser($_GET['id']);
$listing['url'] = $PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url']);
// If listing not found, tell browser not found, else proceed to show listing
if(!$listing['id'] OR ($listing['status'] != 'active' AND $listing['user_id'] != $PMDR->get('Session')->get('user_id') AND @!in_array('admin_login',$_SESSION['admin_permissions']))) {
$PMDR->get('Error',404);
}
if($listing['url'] != URL AND !isset($_GET['action'])) {
$PMDR->get('Error',301);
redirect($listing['url']);
}
if($PMDR->getConfig('snap_javascript')) {
$PMDR->loadJavascript($PMDR->getConfig('snap_javascript'));
}
$listing_locations = $PMDR->get('Locations')->getPath($listing['location_id']);
foreach($listing_locations as $key=>$location) {
$listing['location_'.($key+1)] = $location['title'];
$listing['location_'.($key+1).'_url'] = $PMDR->get('Locations')->getURL($location['id'],$location['friendly_url_path']);
}
$PMDR->set('active_location',array('id'=>$listing['location_id'],'friendly_url_path'=>$listing_locations[(count($listing_locations)-1)]['friendly_url_path']));
$map_country = $PMDR->getConfig('map_country_static') != '' ? $PMDR->getConfig('map_country_static') : $listing[$PMDR->getConfig('map_country')];
$map_state = $PMDR->getConfig('map_state_static') != '' ? $PMDR->getConfig('map_state_static') : $listing[$PMDR->getConfig('map_state')];
$map_city = $PMDR->getConfig('map_city_static') != '' ? $PMDR->getConfig('map_city_static') : $listing[$PMDR->getConfig('map_city')];
// Add listing to favorites
if($_GET['action'] == 'addtofavorites') {
$PMDR->get('Authentication')->authenticate();
$PMDR->get('Favorites')->replace(array('user_id'=>$PMDR->get('Session')->get('user_id'),'listing_id'=>$listing['id']));
$PMDR->addMessage('success',$PMDR->getLanguage('public_listing_favorites_added'),'insert');
}
// Remove listing from favorites
if($_GET['action'] == 'removefromfavorites') {
$PMDR->get('Authentication')->authenticate();
$db->Execute("DELETE FROM ".T_FAVORITES." WHERE user_id=? AND listing_id=?",array($PMDR->get('Session')->get('user_id'),$listing['id']));
$PMDR->addMessage('success',$PMDR->getLanguage('public_listing_favorites_removed'),'delete');
}
// Get listing vcard
if($_GET['action'] == 'vcard') {
$serve = $PMDR->get('ServeFile');
$vcard = $PMDR->get('vCard');
$vcard->addFirstName($listing['title']);
$vcard->addName($listing['title']);
$vcard->addOrganization($listing['title']);
$vcard->addAddress($listing['listing_address1'].' '.$listing['listing_address2'], $map_city, $map_state, $map_country, ($listing['zip_allow'] ? $listing['listing_zip'] : ''));
$vcard->addTelephone($listing['phone']);
$vcard->addFax($listing['fax']);
$vcard->addEmail($listing['mail']);
$vcard->addURL($listing['www']);
$vcard->addNote(BASE_URL);
$serve->serve($listing['friendly_url'].'.vcf', $vcard->getCard());
}
// Get listing PDF
if($_GET['action'] == 'pdf') {
$contact_information = $listing['listing_address1'].'
';
if($listing['listing_address2'] != '') {
$contact_information .= $listing['listing_address2'].'
';
}
$contact_information .= $map_city.', '.$map_state.($listing['zip_allow'] ? ' '.$listing['listing_zip'] : '').'
'.$map_country.'
';
if($listing['phone'] != '') {
$contact_information .= '
'.$PMDR->getLanguage('public_listing_phone').': '.$listing['phone'];
}
if($listing['fax'] != '') {
$contact_information .= '
'.$PMDR->getLanguage('public_listing_fax').': '.$listing['fax'];
}
if(($description = strip_tags(nl2br_replace($listing['description']),'
')) != '') {
$description = '
'.$description;
}
$description .= '
';
$listing_fields = $PMDR->get('Fields')->getFieldsByCategory('listings',$listing['primary_category_id']);
foreach($listing_fields as $key=>$field) {
if($listing['custom_'.$field['id'].'_allow'] AND $listing['custom_'.$field['id']] != '' AND !$field['hidden']) {
$description .= $field['name'].': '.str_replace("\n",', ',$listing['custom_'.$field['id']]).'
';
}
}
if ($listing['www_allow'] AND !empty($listing['www'])) {
$links .= '
'.$PMDR->getLanguage('public_listing_www').'';
}
if ($listing['email_allow'] AND !empty($listing['mail'])) {
$links .= '
'.$PMDR->getLanguage('public_listing_send_message').'';
}
if ($listing['email_friend_allow']) {
$links .= '
'.$PMDR->getLanguage('public_listing_email_friend').'';
}
/** @var TCPDF */
$pdf = $PMDR->get('TCPDF');
$pdf->setJPEGQuality(100);
$pdf->SetCreator(BASE_URL);
$pdf->SetAuthor(BASE_URL);
$pdf->SetTitle($listing['title']);
$pdf->SetSubject($listing['description_short']);
$pdf->SetKeywords($listing['keywords']);
$pdf->SetPrintHeader(false); // No header as we don't want it on every page
$pdf->SetMargins(15, 15, 15); // left, top, right
$pdf->SetAutoPageBreak(TRUE, 10); // margin bottom
$pdf->setImageScale(1.5);
$pdf->SetFooterMargin(10);
$pdf->setFooterFont(Array("dejavusans", '', 12));
$pdf->AliasNbPages();
$pdf->AddPage();
if($PMDR->getLanguage('textdirection') == 'rtl') {
$pdf->setRTL(true);
}
$pdf->SetFont('dejavusans', '', 20);
$pdf->writeHTML($listing['title'].'
');
$pdf->SetFont('dejavusans', '', 12);
if($PMDR->getConfig('pdf_logo') AND $listing['logo_allow']) {
if($logo = find_file(LOGO_PATH.$listing['id'].'.*')) {
$image_details = getimagesize($logo);
$pdf->Image(find_file(LOGO_PATH.$listing['id'].'.*'),$pdf->GetX(),$pdf->GetY(),$pdf->pixelsToUnits($image_details[0]),'','','','N', false);
$pdf->Ln(10);
}
}
$pdf->writeHTML($contact_information.$description.$links,true);
if($PMDR->getConfig('google_apikey') != '' AND $listing['latitude'] != '0.0000000000' AND $listing['longitude'] != '0.0000000000' AND ini_get('allow_url_fopen')) {
$pdf->Ln(5);
//$pdf->Image('http://maps.google.com/staticmap?format=jpg¢er='.$listing['latitude'].','.$listing['longitude'].'&markers='.$listing['latitude'].','.$listing['longitude'].',reda&zoom='.$PMDR->getConfig('map_zoom').'&size=512x512&maptype=mobile&frame=true&key='.$PMDR->getConfig('google_apikey').'&sensor=false',$pdf->GetX(),$pdf->GetY(),$pdf->pixelsToUnits(512),$pdf->pixelsToUnits(512),'JPEG','http://maps.google.com/maps?q='.$listing['latitude'].','.$listing['longitude'],'N', false, 300);
$pdf->Image('http://maps.google.com/staticmap?format=jpg¢er='.$listing['latitude'].','.$listing['longitude'].'&markers='.$listing['latitude'].','.$listing['longitude'].',reda&zoom='.$PMDR->getConfig('map_zoom').'&size=512x512&maptype=mobile&frame=true&sensor=false',$pdf->GetX(),$pdf->GetY(),$pdf->pixelsToUnits(512),$pdf->pixelsToUnits(512),'JPEG','http://maps.google.com/maps?q='.$listing['latitude'].','.$listing['longitude'],'N', false, 300);
}
if(file_exists(PMDROOT.TEMPLATE_PATH.'images/logo.gif')) {
if($image_details = getimagesize(PMDROOT.TEMPLATE_PATH.'images/logo.gif')) {
$pdf_y = $pdf->getPageHeight()-$pdf->getBreakMargin()-$pdf->pixelsToUnits($image_details[1]);
if($pdf->GetY() > $pdf_y) {
$pdf_y = $pdf->GetY();
}
$pdf->Image(PMDROOT.TEMPLATE_PATH.'images/logo.gif', $pdf->GetX(), $pdf_y, '', '', '', BASE_URL, 'N', false, '72', 'C');
unset($pdf_y);
}
}
$pdf->Output($listing['friendly_url'].'.pdf','D');
exit();
}
// If we want to print, use the print.tpl template file
if ($_GET['action'] == 'print') {
$PMDR->set('footer_file','print_footer.tpl');
$PMDR->set('header_file','print_header.tpl');
$PMDR->set('wrapper_file','wrapper_blank.tpl');
$template_content = $PMDR->getNew('Template',PMDROOT.TEMPLATE_PATH.'print.tpl');
} else {
if(trim($listing['header_template_file']) != '' AND file_exists(PMDROOT.TEMPLATE_PATH.$listing['header_template_file'])) {
$PMDR->set('header_file',$listing['header_template_file']);
}
if(trim($listing['footer_template_file']) != '' AND file_exists(PMDROOT.TEMPLATE_PATH.$listing['footer_template_file'])) {
$PMDR->set('footer_file',$listing['footer_template_file']);
}
if(trim($listing['wrapper_template_file']) != '' AND file_exists(PMDROOT.TEMPLATE_PATH.$listing['wrapper_template_file'])) {
$PMDR->set('wrapper_file',$listing['wrapper_template_file']);
}
if(trim($listing['template_file']) != '' AND file_exists(PMDROOT.TEMPLATE_PATH.$listing['template_file'])) {
$template_content = $PMDR->getNew('Template',PMDROOT.TEMPLATE_PATH.$listing['template_file']);
} elseif(file_exists(PMDROOT.TEMPLATE_PATH.'listing_category_'.$listing['primary_category_id'].'.tpl')){
$template_content = $PMDR->getNew('Template',PMDROOT.TEMPLATE_PATH.'listing_category_'.$listing['primary_category_id'].'.tpl');
} else {
$template_content = $PMDR->getNew('Template',PMDROOT.TEMPLATE_PATH.'listing_default.tpl');
}
}
$listing_categories = $PMDR->get('Listings')->getCategories($listing['id']);
foreach($listing_categories as $key=>$category) {
$listing_categories[$key]['path'] = $PMDR->get('Categories')->getPath($category['id']);
$listing_categories[$key]['path_url'] = $PMDR->get('Categories')->getPathDisplay($listing_categories[$key]['path'],'»');
}
// Set page title, and breadcrumb
foreach((array) $listing_categories[$listing['primary_category_id']]['path'] as $category_path) {
$PMDR->setAdd('page_title',$category_path['title']);
$PMDR->setAddArray('breadcrumb',array('link'=>$PMDR->get('Categories')->getURL($category_path['id'],$category_path['friendly_url_path']),'text'=>$category_path['title']));
}
// Set active category used for things such as banners
$PMDR->set('active_category',array('id'=>$listing['primary_category_id'],'friendly_url_path'=>$listing_categories[$listing['primary_category_id']]['friendly_url_path']));
unset($key,$category,$category_path);
// Add the listing to the breadcrumb
$PMDR->setAddArray('breadcrumb',array('link'=>null,'text'=>$listing['title']));
// Set META title
if(!empty($listing['meta_title'])) {
$PMDR->set('meta_title',$listing['meta_title']);
}
$PMDR->setAdd('page_title',$listing['title']);
$PMDR->set('canonical_url',$listing['url']);
// Set META description
if(!empty($listing['meta_description'])) {
$PMDR->set('meta_description',$listing['meta_description']);
} elseif(!empty($listing['description_short'])) {
$PMDR->set('meta_description',$listing['description_short']);
} else {
$meta_description = $listing['title'];
foreach((array) $listing_categories[$listing['primary_category_id']]['path'] as $category) {
$meta_description .= ' '.$category['title'];
}
foreach((array) $listing_locations as $location) {
$meta_description .= ' '.$location['title'];
}
$PMDR->set('meta_description',$PMDR->getConfig('meta_description_default').' '.$meta_description.'.');
unset($meta_description,$category,$location);
}
// Set META keywords
if(!empty($listing['meta_keywords'])) {
$PMDR->set('meta_keywords',$listing['meta_keywords']);
} elseif(!empty($listing['keywords'])) {
$PMDR->set('meta_keywords',$listing['keywords']);
} else {
$meta_keywords = $listing['title'];
foreach((array) $listing_categories[$listing['primary_category_id']]['path'] as $category) {
$meta_keywords .= ','.$category['title'];
}
foreach((array) $listing_locations as $location) {
$meta_keywords .= ','.$location['title'];
}
$PMDR->set('meta_keywords',$PMDR->getConfig('meta_keywords_default').','.$meta_keywords);
unset($meta_keywords,$category,$location);
}
$template_content->set('listing_url',$listing['url']);
$template_content->set('id',$listing['id']);
$template_content->set('title',$listing['title']);
$template_content->set('description',nl2br_replace($PMDR->get('Cleaner')->unclean_html($listing['description'])));
$template_content->set('categories',$listing_categories);
$template_content->set('short_description',substr($listing['description_short'], 0, $listing['short_description_size']));
$template_content->set('new',$PMDR->get('Listings')->ifNew($listing['date']));
$template_content->set('updated',$PMDR->get('Listings')->ifUpdated($listing['date_update']));
$template_content->set('date', $PMDR->get('Dates')->formatDate($listing['date']));
$template_content->set('hot',$PMDR->get('Listings')->ifHot($listing['rating']));
if($listing['ratings_allow']) {
$template_content->set('rating',$listing['rating']);
$template_content->set('votes',$listing['votes']);
if($PMDR->getConfig('ratings_require_review') OR ($PMDR->getConfig('ratings_require_login') AND !$PMDR->get('Session')->get('user_id'))) {
$template_content->set('rating_allowed',false);
} else {
$template_content->set('rating_allowed',true);
}
}
if($listing['phone_allow']) {
$template_content->set('phone', $listing['phone']);
}
if($listing['fax_allow']) {
$template_content->set('fax', $listing['fax']);
}
if($listing['address_allow']) {
$template_content->set('location_text_1', $listing['location_text_1']);
$template_content->set('location_text_2', $listing['location_text_2']);
$template_content->set('location_text_3', $listing['location_text_3']);
$template_content->set('address', ($listing['listing_address1'] != '' ? $listing['listing_address1']."\n" : '').($listing['listing_address2'] != '' ? $listing['listing_address2']."\n" : '').($map_city != '' ? $map_city.', ' : '').($map_state != '' ? $map_state : '').($listing['zip_allow'] ? ' '.$listing['listing_zip'] : '')."\n".$map_country);
$template_content->set('address_line1', $listing['listing_address1']);
$template_content->set('address_line2', $listing['listing_address2']);
foreach($listing_locations as $key=>$value) {
$template_content->set("location_".($key+1),$value['title']);
}
}
$template_content->set('hits', $listing['hits']);
$template_content->set('report_url', BASE_URL.'/contact.php?id='.$listing['id']);
if($listing['addtofavorites_allow']) {
if(!$db->GetOne("SELECT COUNT(*) FROM ".T_FAVORITES." WHERE user_id=? and listing_id=?",array($PMDR->get('Session')->get('user_id'),$listing['id']))) {
$template_content->set('favorites_text',$PMDR->getLanguage('public_listing_favorites_add'));
$template_content->set('favorites_url', BASE_URL.'/listing.php?id='.$listing['id'].'&action=addtofavorites');
} else {
$template_content->set('favorites_text',$PMDR->getLanguage('public_listing_favorites_remove'));
$template_content->set('favorites_url', BASE_URL.'/listing.php?id='.$listing['id'].'&action=removefromfavorites');
}
}
if($listing['pdf_allow']) {
$template_content->set('pdf_url', BASE_URL.'/listing.php?id='.$listing['id'].'&action=pdf');
}
if($listing['vcard_allow']) {
$template_content->set('vcard_url', BASE_URL.'/listing.php?id='.$listing['id'].'&action=vcard');
}
if($listing['zip_allow']) {
$template_content->set('zip',$listing['listing_zip']);
}
if($listing['logo_allow'] AND file_exists(LOGO_PATH.$listing['id'].'.'.$listing['logo_extension'])) {
$template_content->set('logo_url',get_file_url_cdn(LOGO_PATH.$listing['id'].'.'.$listing['logo_extension']));
} elseif(ADDON_WEBSITE_SCREENSHOTS AND $listing['www_screenshot_allow'] AND file_exists(SCREENSHOTS_PATH.$listing['id'].'.jpg')) {
$template_content->set('logo_url',get_file_url_cdn(SCREENSHOTS_PATH.$listing['id'].'.jpg'));
} else {
$template_content->set('logo_url',CDN_URL.TEMPLATE_PATH.'images/noimage.gif');
}
if(ADDON_WEBSITE_SCREENSHOTS AND $listing['www_screenshot_allow'] AND file_exists(SCREENSHOTS_PATH.$listing['id'].'.jpg') AND $listing['www_allow'] AND !empty($listing['www']) AND $_GET['action'] != 'print' AND !$PMDR->getConfig('snap_javascript')) {
$PMDR->loadJavascript('',15);
$PMDR->setAdd('javascript_onload','
$(document).ready(function() {
$("#listing_www").qtip({
style: {
width: '.$PMDR->getConfig('website_screenshot_size').',
border: { width: 5, radius: 5, color: \'#CCCCCC\' },
name: \'light\',
tip: { corner: \'rightTop\', size: { x: 20, y: 15 } }
},
position: { corner: { target: \'leftMiddle\', tooltip: \'rightTop\' } },
content: \'\'
});
});');
}
if ($listing['email_allow'] AND !empty($listing['mail'])) {
$template_content->set('mail',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/send-message.html','listing_email.php'));
}
if($listing['classifieds_limit']) {
$template_content->set('classifieds_count',$db->GetOne("SELECT COUNT(*) AS count FROM ".T_CLASSIFIEDS." WHERE listing_id=? AND (expire_date > '".date('Y-m-d')."' OR expire_date='0000-00-00')",array($listing['id'])));
$template_content->set('classifieds_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/classifieds.html','listing_classifieds.php'));
}
if($listing['images_limit']) {
$template_content->set('images_count',$db->GetOne("SELECT COUNT(*) AS count FROM ".T_IMAGES." WHERE listing_id=?",array($listing['id'])));
$template_content->set('images_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/images.html','listing_images.php'));
}
if($listing['documents_limit']) {
$template_content->set('documents_count',$db->GetOne("SELECT COUNT(*) AS count FROM ".T_DOCUMENTS." WHERE listing_id=?",array($listing['id'])));
$template_content->set('documents_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/documents.html','listing_documents.php'));
}
if($listing['print_allow']) {
$template_content->set('print', 'JavaScript:newWindow(\''.BASE_URL.'/listing.php?id='.$listing['id'].'&action=print\',\'popup\','.$PMDR->getConfig('print_window_width').','.$PMDR->getConfig('print_window_height').',\'\')');
}
if ($listing['email_friend_allow']) {
$template_content->set('email_friend', $PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/send-message-friend.html','listing_email_friend.php'));
}
if ($listing['reviews_allow']) {
$reviews_count = $db->GetOne("SELECT COUNT(*) AS count FROM ".T_REVIEWS." WHERE listing_id=? AND status=? ORDER BY id DESC",array($listing['id'],'active'));
$template_content->set('reviews_count',$reviews_count);
$template_content->set('reviews_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/reviews.html','listing_reviews.php'));
$template_content->set('reviews_add_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/add-review.html','listing_reviews_add.php'));
}
if ($listing['claim_allow'] AND !$listing['claimed']) {
$template_content->set('claim_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/claim.html','listing_claim.php'));
}
if ($listing['suggestion_allow']) {
$template_content->set('suggestion_url',$PMDR->get('Listings')->getURL($listing['id'],$listing['friendly_url'],'','/suggestion.html','listing_suggestion.php'));
}
$PMDR->loadJavascript('');
$PMDR->loadJavascript('');
$template_content->set('addthis_url','http://www.addthis.com/bookmark.php?v=20');
if($listing['www_allow'] AND !empty($listing['www'])) {
if ($_GET['action'] == 'print') {
$template_content->set('www',$listing['www']);
} else {
if($PMDR->getConfig('snap_javascript')) {
$class = 'class="snap_shots" ';
$template_content->set('www_class',$class);
}
if($PMDR->getConfig('js_click_counting')) {
$template_content->set('www_url',$listing['www']);
$template_content->set('www_javascript','onclick="$.ajax({async: false, cache: false, timeout: 30000, data: ({ action: \'add_click\', id: '.$listing['id'].' })});"');
} else {
if (MOD_REWRITE) {
$template_content->set('www_url',BASE_URL.'/out-'.$listing['id'].'.html');
} else {
$template_content->set('www_url',BASE_URL.'/out.php?listing_id='.$listing['id']);
}
}
if(strtotime($listing['pagerank_expiration']) <= time() AND !empty($listing['www'])) {
if($listing['pagerank'] = $PMDR->get('PageRank')->getRank($listing['www'])) {
$db->Execute("UPDATE LOW_PRIORITY ".T_LISTINGS." SET pagerank=?, pagerank_expiration=DATE_ADD(NOW(),INTERVAL 30 DAY) WHERE id=?",array((int) $listing['pagerank'],$listing['id']));
}
}
$template_content->set('pagerank',$listing['pagerank']);
}
}
$custom_fields_exclude = array();
if($PMDR->getConfig('skype_field') AND !empty($listing[$PMDR->getConfig('skype_field')]) AND $listing[$PMDR->getConfig('skype_field').'_allow']) {
$PMDR->loadJavascript('');
$template_content->set('skype_url','skype:'.$listing[$PMDR->getConfig('skype_field')].'?call');
$custom_fields_exclude[] = $PMDR->getConfig('skype_field');
}
// Get custom field groups along with the fields based on the listing category
$custom_fields_groups = $PMDR->get('Fields_Groups')->getFieldGroupsByCategory('listings',$listing['primary_category_id']);
// Process the field groups and fields and send them to the template
foreach($custom_fields_groups as $group_id=>$custom_fields_group) {
$custom_fields_groups[$group_id]['empty'] = true;
foreach($custom_fields_group['fields'] AS $field_key=>$custom_field) {
// Remove any fields not allowed by this listing product and remove any hidden fields
if(!$listing['custom_'.$custom_field['id'].'_allow'] OR $custom_field['hidden'] OR in_array('custom_'.$custom_field['id'],$custom_fields_exclude)) {
unset($custom_fields_group['fields'][$field_key]);
} else {
// Send custom field name and custom field value to the template for individual use (i.e. $custom_1_name and $custom_1)
$template_content->set('custom_'.$custom_field['id'].'_name',$custom_field['name']);
if($custom_field['type'] == 'date') {
$template_content->set('custom_'.$custom_field['id'],$PMDR->get('Dates')->formatDate($listing['custom_'.$custom_field['id']]));
} else {
$template_content->set('custom_'.$custom_field['id'],$listing['custom_'.$custom_field['id']]);
}
// We set an empty flag so we can determine if the group is completely empty or not.
if(!empty($listing['custom_'.$custom_field['id']])) {
$custom_fields_groups[$group_id]['empty'] = false;
}
}
}
// If the group no longer has any fields in it, we remove it from the array
if(count(array_filter($custom_fields_group['fields'])) == 0) {
unset($custom_fields_groups[$group_id]);
} else {
// Send the custom field group title to the template for individual use (i.e. $custom_group_1_title)
$template_content->set('custom_group_'.$group_id.'_title',$custom_fields_group['title']);
}
}
$template_content->set('custom_fields_groups',$custom_fields_groups);
unset($custom_fields_groups);
unset($custom_fields_group);
unset($field_id);
unset($group_id);
unset($custom_field);
if($listing['map_allow']) {
/** @var Map */
$map = $PMDR->get($PMDR->getConfig('map_type').'_Map');
if($PMDR->getConfig('map_display_type') == 'link') {
$map_output = $PMDR->get('Template',PMDROOT.TEMPLATE_PATH.'blocks/listing_map_link.tpl');
$map_output->set('url',$map->getMapURL($listing['listing_address1'],$map_city,$map_state,$map_country,$listing['listing_zip']));
} else {
$map->lookupService = $PMDR->getConfig('geocoding_service');
$map->apiKeyGeoCoding = $PMDR->getConfig($map->lookupService.'_apikey');
$map->zoomLevel = $PMDR->getConfig('map_zoom');
//$map->script = 'infowindow.open(map,marker0);';
$map_popup = $PMDR->get('Template',PMDROOT.TEMPLATE_PATH.'blocks/map_popup.tpl');
$map_popup->set('title',$listing['title']);
$map_popup->set('address', ($listing['listing_address1'] != '' ? $listing['listing_address1']."\n" : '').($listing['listing_address2'] != '' ? $listing['listing_address2']."\n" : '').($map_city != '' ? $map_city.', ' : '').($map_state != '' ? $map_state : '').($listing['zip_allow'] ? ' '.$listing['listing_zip'] : '')."\n".$map_country);
if($listing['latitude'] != '0.0000000000' AND $listing['longitude'] != '0.0000000000') {
$map_popup->set('directions_begin',$listing['latitude'].','.$listing['longitude']);
$map->addMarkerByCoords($listing['longitude'], $listing['latitude'], $listing['title'],$map_popup->render());
} else {
$map_popup->set('directions_begin',$map_city.','.$map_state.','.$map_country.','.$listing['listing_zip']);
if($map->addMarkerByAddress($listing['listing_address1'],$map_city,$map_state,$map_country,$listing['listing_zip'],$listing['title'],$map_popup->render())) {
$db->Execute("UPDATE ".T_LISTINGS." SET longitude=?, latitude=? WHERE id=?",array($map->markers[0]['lon'],$map->markers[0]['lat'],$listing['id']));
}
}
unset($map_popup);
if(count($map->markers)) {
$PMDR->loadJavascript($map->getHeaderJS());
$PMDR->loadJavascript($map->getMapJS());
$PMDR->setAdd('javascript_onload','mapOnLoad();');
$map_output = $map->getMap();
}
}
$template_content->set('map',$map_output);
if($listing['latitude'] != '0.0000000000' AND $listing['longitude'] != '0.0000000000') {
$PMDR->set('meta_geo_position',$listing['latitude'].','.$listing['longitude']);
}
}
if (($ip = get_ip_address()) != $listing['counterip']) {
$db->Execute('UPDATE LOW_PRIORITY '.T_LISTINGS.' SET counterip=?, hits=hits+1 WHERE id=?',array($ip,$listing['id']));
}
// Get the images from the database
$records = $PMDR->get('Images')->getRows(array('listing_id'=>$listing['id']),array('ordering'=>'ASC'),$table_list->page_data['limit1'],$table_list->page_data['limit2']);
// Looks through the images and get the thumbnail url, image url, and description
foreach($records as $key=>$record) {
$records[$key]['thumb'] = get_file_url_cdn(IMAGES_THUMBNAILS_PATH.$record['id'].'.'.$record['extension']);
$records[$key]['image'] = get_file_url_cdn(IMAGES_PATH.$record['id'].'.'.$record['extension']);
$records[$key]['description'] = nl2br_replace($record['description']);
}
// Set the template variables
$template_content->set('images',$records);
$PMDR->get('Plugins')->run_hook('listing_end');
include(PMDROOT.'/includes/template_setup.php');
?>