<?php
/**
 * The template to display the property's single page
 *
 * @package WordPress
 * @subpackage ThemeREX Addons
 * @since v1.6.22
 */

wp_enqueue_script('jquery-ui-accordion', false, array('jquery', 'jquery-ui-core'), null, true);
if (trx_addons_get_option('properties_single_style') == 'tabs')
	wp_enqueue_script('jquery-ui-tabs', false, array('jquery', 'jquery-ui-core'), null, true);

get_header();

// Post meta
			$seventrees_components = seventrees_array_get_keys_by_value(seventrees_get_theme_option('meta_parts'));
			$seventrees_counters = seventrees_array_get_keys_by_value(seventrees_get_theme_option('counters'));
		    $res = seventrees_get_post_meta_array( array(
		        'components' => $seventrees_components,
		        'counters' => $seventrees_counters,
		        'seo' => false,
		        'echo' => false
		    )
		    );


while ( have_posts() ) { the_post();
	$trx_addons_meta = get_post_meta(get_the_ID(), 'trx_addons_options', true);
	?>
	<article id="post-<?php the_ID(); ?>" <?php post_class( 'properties_page itemscope' ); trx_addons_seo_snippets('', 'Article'); ?>>

		<?php do_action('trx_addons_action_before_article', 'properties.single'); ?>
		
		<section class="post_item properties_page_section properties_page_header"><?php
			// Image
			if ( !trx_addons_sc_layouts_showed('featured') && has_post_thumbnail() ) {
				?><div  class="properties_page_featured">
			
			<?php
					the_post_thumbnail( trx_addons_get_thumb_size('huge'), trx_addons_seo_image_params(array(
								'alt' => the_title_attribute( array( 'echo' => false ) )
								))
							);
				
				?></div><?php
				if (!empty($trx_addons_meta['gallery'])) {
					$trx_addons_gallery = explode('|', $trx_addons_meta['gallery']);
					if (is_array($trx_addons_gallery)) {
						?><div class="properties_page_gallery"><?php
							array_unshift($trx_addons_gallery, get_post_thumbnail_id($id));
							$i = 0;
							foreach($trx_addons_gallery as $trx_addons_image) {
								$i++;
								if ($trx_addons_image != '') {
									$trx_addons_thumb = trx_addons_get_attachment_url($trx_addons_image, trx_addons_get_thumb_size('tiny'));
									$trx_addons_image = trx_addons_get_attachment_url($trx_addons_image, trx_addons_get_thumb_size('huge'));
									if (!empty($trx_addons_thumb)) {
										$attr = trx_addons_getimagesize($trx_addons_thumb);
										?><span class="properties_page_gallery_item<?php if ($i==1) echo " properties_page_gallery_item_active"; ?>" data-image="<?php echo esc_url($trx_addons_image); ?>"><?php
											?><img src="<?php echo esc_url($trx_addons_thumb); ?>" alt="<?php the_title_attribute() ?>"<?php
												if (!empty($attr[3])) echo ' '.trim($attr[3]);
											?>><?php
										?></span><?php
									}
								}
							}
						?></div><?php
					}
				}
			}
			
			// Title
			if ( true || !trx_addons_sc_layouts_showed('title') ) {
				?><div class="properties_page_title_wrap">
					<?php
					// Price
					if (!empty($trx_addons_meta['price']) || !empty($trx_addons_meta['price2'])) {
						?><div class="properties_page_title_price"><h5><?php
							trx_addons_get_template_part(TRX_ADDONS_PLUGIN_CPT . 'properties/tpl.properties.parts.price.php',
															'trx_addons_args_properties_price',
															array('meta' => $trx_addons_meta)
														);
						?></h5></div><?php
					}
					?>
					<h4 class="properties_page_title">
						<?php the_title(); ?>
						<span class="properties_page_status"><?php
							trx_addons_show_layout(trx_addons_get_post_terms('', get_the_ID(), TRX_ADDONS_CPT_PROPERTIES_TAXONOMY_STATUS));
						?></span>
					</h4>
					<?php
					// Meta
					?>
					<div class="meta_bottom">
						<?php
						// Post meta part 2
						if (!empty($res['views'])){seventrees_show_layout($res['views']); }						
						if (!empty($res['likes'])){seventrees_show_layout($res['likes']); }
						if (!empty($res['comments'])){seventrees_show_layout($res['comments']);}
						if (!empty($res['share'])){seventrees_show_layout($res['share']); }
						?>
						</div>
					<?php
					
					// Address
					if (!empty($trx_addons_meta['address'])) {
						?><div class="properties_page_title_address"><?php
							trx_addons_get_template_part(TRX_ADDONS_PLUGIN_CPT . 'properties/tpl.properties.parts.address.php',
															'trx_addons_args_properties_address',
															array('meta' => $trx_addons_meta)
														);
						?></div><?php
					}
					
			}
		?></section><?php

		
		// Section's titles
		$trx_addons_section_titles = array(
			'description' => esc_html__('Açıklama', 'seventrees'),
			'details' => esc_html__('Detaylar', 'seventrees'),
			'features' => esc_html__('Özellikler', 'seventrees'),
			'floor_plans' => esc_html__('Kat Planı', 'seventrees'),
			'attachments' => esc_html__('Ek', 'seventrees'),
			'video' => esc_html__('Video', 'seventrees'),
			'virtual_tour' => esc_html__('Virtual tour', 'seventrees'),
			'contacts' => esc_html__('İletişim', 'seventrees'),
			'googlemap' => esc_html__('Google map', 'seventrees')
		);
		$trx_addons_tabs_id = 'properties_page_tabs';

		// Tabs
		if (trx_addons_get_option('properties_single_style') == 'tabs') {
			if (empty($trx_addons_meta['floor_plans_enable'])
				|| empty($trx_addons_meta['floor_plans']) 
				|| !is_array($trx_addons_meta['floor_plans'])
				|| empty($trx_addons_meta['floor_plans'][0]['title']))
				unset($trx_addons_section_titles['floor_plans']);
			if (empty($trx_addons_meta['attachments']))
				unset($trx_addons_section_titles['attachments']);
			if (empty($trx_addons_meta['video']))
				unset($trx_addons_section_titles['video']);
			if (empty($trx_addons_meta['virtual_tour']))
				unset($trx_addons_section_titles['virtual_tour']);
			if (empty($trx_addons_meta['show_map'])
				|| empty($trx_addons_meta['location']))
				unset($trx_addons_section_titles['googlemap']);
			if (empty($trx_addons_meta['agent_type']) 
				|| $trx_addons_meta['agent_type']=='none' 
				|| ($trx_addons_meta['agent_type']!='author' && $trx_addons_meta['agent']==0))
				unset($trx_addons_section_titles['contacts']);
			?><div class="trx_addons_tabs properties_page_tabs">
				<ul class="trx_addons_tabs_titles"><?php
					foreach ($trx_addons_section_titles as $trx_addons_section_slug => $trx_addons_section_title) {
						$trx_addons_tab_id = $trx_addons_tabs_id.'_'.$trx_addons_section_slug;
						$trx_addons_tab_active = trx_addons_get_value_gp('tab')==$trx_addons_section_slug
										? ' data-active="true"' 
										: '';
						?><li<?php
							if (trx_addons_get_value_gp('tab')==$trx_addons_section_slug)
								echo ' data-active="true"';
							?>><a href="<?php echo esc_url(trx_addons_get_hash_link('#'.$trx_addons_tab_id.'_content')); ?>"><?php
								echo esc_html($trx_addons_section_title);
							?></a></li><?php
					}
				?></ul><?php
		}


		// Post content
		?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_description'); ?>_content" class="properties_page_section properties_page_content entry-content"<?php trx_addons_seo_snippets('articleBody'); ?>><?php
			if (trx_addons_get_option('properties_single_style') == 'tabs') {
				?><h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['description']); ?></h4><?php
			}
			the_content( );
		?></section><!-- .entry-content --><?php


		// Details
		?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_details'); ?>_content" class="properties_page_section properties_page_details">
			<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['details']); ?></h4>
			<div class="details_columns">
			<?php
			// Area size
			if (!empty($trx_addons_meta['area_size'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('Alan:', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php
						trx_addons_show_layout($trx_addons_meta['area_size']
												. ($trx_addons_meta['area_size_prefix'] 
														? ' ' . trx_addons_prepare_macros($trx_addons_meta['area_size_prefix'])
														: ''
													)
												);
					?></span>
				</span><?php
			}
			// Land size
		/*	if (!empty($trx_addons_meta['land_size'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('Land size:', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php
						trx_addons_show_layout($trx_addons_meta['land_size']
												. ($trx_addons_meta['land_size_prefix'] 
														? ' ' . trx_addons_prepare_macros($trx_addons_meta['land_size_prefix'])
														: ''
													)
												);
					?></span>
				</span><?php
			}*/
			// Bedrooms
			if (!empty($trx_addons_meta['bedrooms'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('Oda:', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php echo esc_html($trx_addons_meta['bedrooms']); ?></span>
				</span><?php
			}
			// Bathrooms
			if (!empty($trx_addons_meta['bathrooms'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('Banyo:', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php echo esc_html($trx_addons_meta['bathrooms']); ?></span>
				</span><?php
			}
			// Garages
			if (!empty($trx_addons_meta['garages'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('Garaj:', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php
						trx_addons_show_layout($trx_addons_meta['garages']
												. ($trx_addons_meta['garage_size'] 
														? ' (' . trx_addons_prepare_macros($trx_addons_meta['garage_size']) . ')'
														: ''
													)
												);
					?></span>
				</span><?php
			}
			// Year built
			if (!empty($trx_addons_meta['built'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('Bina Yaşı', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php trx_addons_show_layout($trx_addons_meta['built']); ?></span>
				</span><?php
			}
			// ID
			if (!empty($trx_addons_meta['id'])) {
				?><span class="properties_page_section_item">
					<span class="properties_page_label"><?php esc_html_e('İlan No:', 'seventrees'); ?></span>
					<span class="properties_page_data"><?php trx_addons_show_layout($trx_addons_meta['id']); ?></span>
				</span><?php
			}			
			// Additional details
			if (!empty($trx_addons_meta['details_enable']) && !empty($trx_addons_meta['details']) && is_array($trx_addons_meta['details'])) {
				foreach ($trx_addons_meta['details'] as $detail) {
					if (!empty($detail['title'])) {
						?><span class="properties_page_section_item">
							<span class="properties_page_label"><?php
								trx_addons_show_layout(trx_addons_prepare_macros($detail['title'])); 
							?>:</span>
							<span class="properties_page_data"><?php 
								trx_addons_show_layout(trx_addons_prepare_macros($detail['value'])); 
							?></span>
						</span><?php
					}
				}
			}
		?>
		</div>
		</section><!-- .properties_page_details --><?php

		// Features
		?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_features'); ?>_content" class="properties_page_section properties_page_features">
			<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['features']); ?></h4>
			<div class="properties_page_features_list">
				<?php trx_addons_show_layout(trx_addons_get_post_terms('', get_the_ID(), TRX_ADDONS_CPT_PROPERTIES_TAXONOMY_FEATURES)); ?>
			</div>
		</section><!-- .properties_page_features --><?php

		// Floor plans
		if (!empty($trx_addons_meta['floor_plans_enable']) && !empty($trx_addons_meta['floor_plans']) 
			&& is_array($trx_addons_meta['floor_plans']) && !empty($trx_addons_meta['floor_plans'][0]['title'])) {
			?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_floor_plans'); ?>_content" class="properties_page_section properties_page_floor_plans">
				<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['floor_plans']); ?></h4>
				<div class="properties_page_floor_plans_list trx_addons_accordion" data-collapsible="true"><?php
					foreach ($trx_addons_meta['floor_plans'] as $plan) {
						?><div class="properties_page_floor_plans_list_item">
							<h5 class="properties_page_floor_plans_list_item_title"><?php
								// Plan's title
								?><span class="properties_page_floor_plans_list_item_title_part">
									<span class="properties_page_data"><?php echo esc_html($plan['title']); ?></span>
								</span><?php
								// Floor size
								if (!empty($plan['area'])) {
									?><span class="properties_page_floor_plans_list_item_title_part">
										<span class="properties_page_label"><?php esc_html_e('Size:', 'seventrees'); ?></span>
										<span class="properties_page_data"><?php echo esc_html($plan['area']); ?></span>
									</span><?php
								}
								// Bedrooms
								if (!empty($plan['bedrooms'])) {
									?><span class="properties_page_floor_plans_list_item_title_part">
										<span class="properties_page_label"><?php esc_html_e('Oda:', 'seventrees'); ?></span>
										<span class="properties_page_data"><?php echo esc_html($plan['bedrooms']); ?></span>
									</span><?php
								}
								// Bathrooms
								if (!empty($plan['bathrooms'])) {
									?><span class="properties_page_floor_plans_list_item_title_part">
										<span class="properties_page_label"><?php esc_html_e('Banyo:', 'seventrees'); ?></span>
										<span class="properties_page_data"><?php echo esc_html($plan['bathrooms']); ?></span>
									</span><?php
								}
							?></h5>
							<div class="properties_page_floor_plans_list_item_content"><?php
								// Image
								if (!empty($plan['image'])) {
									$trx_addons_image = trx_addons_get_attachment_url($plan['image'], trx_addons_get_thumb_size('huge'));
									if (!empty($trx_addons_image)) {
										?><div class="properties_page_floor_plans_list_item_image"><?php
											$attr = trx_addons_getimagesize($trx_addons_image);
											?><img src="<?php echo esc_url($trx_addons_image); ?>" alt="<?php the_title_attribute() ?>"<?php
												if (!empty($attr[3])) echo ' '.trim($attr[3]);
											?>><?php
										?></div><?php
									}
								}
								// Description
								if (!empty($plan['description'])) {
									?><div class="properties_page_floor_plans_list_item_description"><?php
										echo wp_kses($plan['description'], 'seventrees_kses_content');
									?></div><?php
								}
							?></div>
						</div><?php
					}
				?></div>
			</section><!-- .properties_page_floor_plans --><?php
		}

		// Attachments
		if (!empty($trx_addons_meta['attachments'])) {
			$trx_addons_meta['attachments'] = explode('|', $trx_addons_meta['attachments']);
			if (is_array($trx_addons_meta['attachments']) && count($trx_addons_meta['attachments'])>0) {
				?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_attachments'); ?>_content" class="properties_page_section properties_page_attachments">
					<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['attachments']); ?></h4><?php
					if (!empty($trx_addons_meta['attachments_description'])) {
						?><div class="properties_page_section_description"><?php
							echo wp_kses(nl2br($trx_addons_meta['attachments_description']), 'seventrees_kses_content');
						?></div><?php
					}
					?><div class="properties_page_attachments_list"><?php
						foreach ($trx_addons_meta['attachments'] as $file) {
							?><a href="<?php echo esc_url($file); ?>"><?php	echo esc_html(basename($file));	?></a><?php
						}
					?></div>
				</section><!-- .properties_page_attachments --><?php
			}
		}


		// Video promo
		if (!empty($trx_addons_meta['video'])) {
			?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_video'); ?>_content" class="properties_page_section properties_page_video">
				<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['video']); ?></h4><?php
					if (!empty($trx_addons_meta['video_description'])) {
						?><div class="properties_page_section_description"><?php
							echo wp_kses(nl2br($trx_addons_meta['video_description']), 'seventrees_kses_content');
						?></div><?php
					}
				?><div class="properties_page_video_wrap"><?php
					trx_addons_show_layout(trx_addons_get_video_layout(array(
																			'link' => $trx_addons_meta['video']
																		)));
				?></div>
			</section><!-- .properties_page_video --><?php
		}


		// Virtual tour
		if (!empty($trx_addons_meta['virtual_tour'])) {
			?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_virtual_tour'); ?>_content" class="properties_page_section properties_page_virtual_tour">
				<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['virtual_tour']); ?></h4><?php
					if (!empty($trx_addons_meta['virtual_tour_description'])) {
						?><div class="properties_page_section_description"><?php
							echo wp_kses(nl2br($trx_addons_meta['virtual_tour_description']), 'seventrees_kses_content');
						?></div><?php
					}
				?><div class="properties_page_virtual_tour_wrap"><?php
					if (strpos($trx_addons_meta['virtual_tour'], '<')===false) {
						?><iframe src="<?php
							echo esc_url($trx_addons_meta['virtual_tour']);
							?>" frameborder="0" width="1170" height="658"></iframe><?php
					} else {
						if ( strpos($trx_addons_meta['virtual_tour'], '</iframe>') ) {
							echo trim( $iframe = substr($trx_addons_meta['virtual_tour'], strpos($trx_addons_meta['virtual_tour'], '<iframe>'), strpos($trx_addons_meta['virtual_tour'], '</iframe>') + 9) );
							$meta = substr($trx_addons_meta['virtual_tour'], strpos($trx_addons_meta['virtual_tour'], '</iframe>') + 9);
						} else {
							trx_addons_show_layout($trx_addons_meta['virtual_tour']);
						}
					}
				?></div>
				<?php if ( $meta ) { ?>
					<div class="properties_page_virtual_tour_meta"><?php echo trim($meta) ?></div>
				<?php } ?>
			</section><!-- .properties_page_virtual_tour --><?php
		}


		// Google map
		if (!empty($trx_addons_meta['show_map']) && !empty($trx_addons_meta['location'])) {
			?><section id="<?php echo esc_attr($trx_addons_tabs_id.'_attachments'); ?>_content" class="properties_page_section properties_page_attachments">
				<h4 class="properties_page_section_title"><?php echo esc_html($trx_addons_section_titles['googlemap']); ?></h4><?php
				?><div class="properties_page_map"><?php
					trx_addons_show_layout(trx_addons_sc_properties(array(
																		'type' => 'googlemap',
																		'ids' => get_the_ID()
																		)));
				?></div>
			</section><!-- .properties_page_googlemap --><?php
		}

		// Close tabs wrapper
		if (trx_addons_get_option('properties_single_style') == 'tabs') {
			?></div><!-- /.trx_addons_tabs properties_page_tabs --><?php
		}

		do_action('trx_addons_action_after_article', 'properties.single');

	?></article><?php
	
	
	// Related items
	$taxonomies = array();
	

	// Select objects in same city
	$terms = get_the_terms(get_the_ID(), TRX_ADDONS_CPT_PROPERTIES_TAXONOMY_CITY);
	if ( !empty( $terms ) ) {
		$taxonomies[TRX_ADDONS_CPT_PROPERTIES_TAXONOMY_CITY] = array();
		foreach( $terms as $term )
			$taxonomies[TRX_ADDONS_CPT_PROPERTIES_TAXONOMY_CITY][] = $term->term_id;
	}

	$trx_addons_related_style   = explode('_', trx_addons_get_option('properties_blog_style'));
	$trx_addons_related_type    = $trx_addons_related_style[0];
	$trx_addons_related_columns = empty($trx_addons_related_style[1]) ? 1 : max(1, $trx_addons_related_style[1]);
	
	trx_addons_get_template_part('templates/tpl.posts-related.php',
										'trx_addons_args_related',
										apply_filters('trx_addons_filter_args_related', array(
															'class' => 'properties_page_related sc_properties sc_properties_'.esc_attr($trx_addons_related_type),
															'posts_per_page' => $trx_addons_related_columns,
															'columns' => $trx_addons_related_columns,
															'template' => TRX_ADDONS_PLUGIN_CPT . 'properties/tpl.properties.'.trim($trx_addons_related_type).'-item.php',
															'template_args_name' => 'trx_addons_args_sc_properties',
															'post_type' => TRX_ADDONS_CPT_PROPERTIES_PT,
															'taxonomies' => $taxonomies
															)
													)
									);

	// If comments are open or we have at least one comment, load up the comment template.
	if ( comments_open() || get_comments_number() ) {
		comments_template();
	}
}

get_footer();
?> 

PHP Online Compiler

Write, Run & Share PHP code online using OneCompiler's PHP online compiler for free. It's one of the robust, feature-rich online compilers for PHP language, running on the latest version 7. Getting started with the OneCompiler's PHP compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as PHP and start coding.

Taking inputs (stdin)

OneCompiler's PHP online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample PHP program which takes name as input and prints hello message with your name.

<?php
	fscanf(STDIN, "%s\n", $name);           
    echo "Hello ".$name.".\n";
?>

About PHP

PHP(Hypertext Preprocessor) is widely used server sripting language by Rasmus Lerdorf in the year 1994.

Key features

  • Free
  • powerful tool for making dynamic and interactive web pages
  • can integrate with almost all popular databases like MySQL, PostgreSQL, Oracle, Sybase, Informix, Microsoft SQL Server etc.
  • C like Syntax and easy to learn.
  • Object oriented scripting language.
  • easily embeddable into HTML
  • Loosely typed language.

Syntax help

Variables

In PHP, there is no need to explicitly declare variables to reserve memory space. When you assign a value to a variable, declaration happens automatically. Variables are case-sensitive in PHP.

$variable_name = value;  

Loops

1. IF Family:

If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions.

If

if(conditional-expression){    
//code    
} 

If-else

if(conditional-expression){  
//code if condition is true  
} else {  
//code if condition is false  
} 

Nested-If-else

if(condition-expression1) {  
    //code if above condition is true  
} elseif(condition-expression2){  
    //code if above condition is true  
}  
elseif(condition-expression3) {  
    //code if above condition is true  
}  
...  
else {  
    //code if all the conditions are false  
}  

2. Switch:

Switch is used to execute one set of statement from multiple conditions.

switch(conditional-expression) {    
case value1:    
 // code if the above value is matched    
 break;  // optional  
case value2:    
 // code if the above value is matched    
 break;  // optional  
...    
    
default:     
 // code to be executed when all the above cases are not matched;    
} 
 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  // code  
} 

For-each:

// you can use any of the below syntax
foreach ($array as $element-value) {  
    //code  
}

foreach ($array as $key => $element-value) {   
    //code 
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {  
 // code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

How to define a Function

function function_name(parameters) {  
  //code
}

How to call a Function

function_name (parameters)