1
<?php
2
defined('ABSPATH') || exit;
3
require_once __DIR__ . '/elementor-widget-base.php';
4
if (!class_exists('FRESH_OO_Property_Header_Widget') && class_exists('FRESH_OO_Widget_Base')) {
5
class FRESH_OO_Property_Header_Widget extends FRESH_OO_Widget_Base {
6
public function get_name(): string { return 'fresh-oo-property-header'; }
7
public function get_title(): string { return 'onOffice Objektkopf'; }
8
public function get_icon(): string { return 'eicon-site-title'; }
9
public function get_keywords(): array { return ['onoffice','hero','titel','objektkopf','immobilie']; }
10
11
protected function register_controls(): void {
12
$this->start_controls_section('content',['label'=>'Objektkopf']);
13
$this->add_control('title_source',['label'=>'Titel','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'post','options'=>['post'=>'WordPress-Titel','field'=>'onOffice Objekttitel']]);
14
$this->add_control('title_tag',['label'=>'Titel HTML-Tag','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'h1','options'=>['h1'=>'H1','h2'=>'H2','h3'=>'H3','div'=>'DIV']]);
15
$this->add_control('show_location',['label'=>'Ort anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
16
$this->add_control('location_mode',['label'=>'Ortsangabe','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'city','options'=>['city'=>'Ort / Stadtteil','postal'=>'PLZ + Ort','street'=>'Straße + PLZ + Ort'],'condition'=>['show_location'=>'yes']]);
17
$this->add_control('show_meta',['label'=>'Objekt-Meta anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
18
$this->add_control('meta_show_year',['label'=>'Baujahr im Objektkopf','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'','condition'=>['show_meta'=>'yes']]);
19
$this->add_control('meta_show_floor',['label'=>'Etage im Objektkopf','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'','condition'=>['show_meta'=>'yes']]);
20
$this->add_control('meta_show_condition',['label'=>'Zustand im Objektkopf','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'','condition'=>['show_meta'=>'yes']]);
21
$this->add_control('show_price',['label'=>'Preis anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
22
$this->add_control('show_period',['label'=>'/ Monat bei Miete','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes','condition'=>['show_price'=>'yes']]);
23
$this->add_control('show_secondary',['label'=>'Passenden Zusatzpreis anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes','condition'=>['show_price'=>'yes']]);
24
$this->add_control('show_commission',['label'=>'Provision anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes','condition'=>['show_price'=>'yes']]);
25
$this->add_control('show_number',['label'=>'Objektnummer anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'']);
26
$this->add_control('price_on_request',['label'=>'Preis-Fallback','type'=>\Elementor\Controls_Manager::TEXT,'default'=>'Preis auf Anfrage','condition'=>['show_price'=>'yes']]);
27
$this->end_controls_section();
28
29
$this->start_controls_section('layout',['label'=>'Layout']);
30
$this->add_control('layout_mode',['label'=>'Darstellung','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'split','options'=>['stacked'=>'Untereinander','split'=>'Titel links · Preis rechts','centered'=>'Zentriert'],'prefix_class'=>'fresh-oo-header--']);
31
$this->add_responsive_control('align',['label'=>'Textausrichtung','type'=>\Elementor\Controls_Manager::CHOOSE,'options'=>['left'=>['title'=>'Links','icon'=>'eicon-text-align-left'],'center'=>['title'=>'Mitte','icon'=>'eicon-text-align-center'],'right'=>['title'=>'Rechts','icon'=>'eicon-text-align-right']],'default'=>'left','selectors'=>['{{WRAPPER}} .fresh-oo-property-header'=>'text-align:{{VALUE}};']]);
32
$this->add_responsive_control('gap',['label'=>'Abstand','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>0,'max'=>80]],'default'=>['size'=>14],'selectors'=>['{{WRAPPER}} .fresh-oo-property-header'=>'gap:{{SIZE}}{{UNIT}};','{{WRAPPER}} .fresh-oo-property-header__main'=>'gap:{{SIZE}}{{UNIT}};']]);
33
$this->end_controls_section();
34
35
$this->start_controls_section('style_box',['label'=>'Box','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
36
$this->add_common_card_style_controls('box','{{WRAPPER}} .fresh-oo-property-header');
37
$this->end_controls_section();
38
$this->start_controls_section('style_title',['label'=>'Titel & Ort','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
39
$this->add_control('title_color',['label'=>'Titel','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__title'=>'color:{{VALUE}};']]);
40
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'title_typo','selector'=>'{{WRAPPER}} .fresh-oo-property-header__title']);
41
$this->add_control('location_color',['label'=>'Ort','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__location'=>'color:{{VALUE}};']]);
42
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'location_typo','selector'=>'{{WRAPPER}} .fresh-oo-property-header__location']);
43
$this->end_controls_section();
44
$this->start_controls_section('style_meta',['label'=>'Meta-Badges','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
45
$this->add_control('meta_color',['label'=>'Text','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__badge'=>'color:{{VALUE}};']]);
46
$this->add_control('meta_bg',['label'=>'Hintergrund','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__badge'=>'background-color:{{VALUE}};']]);
47
$this->add_group_control(\Elementor\Group_Control_Border::get_type(),['name'=>'meta_border','selector'=>'{{WRAPPER}} .fresh-oo-property-header__badge']);
48
$this->add_responsive_control('meta_radius',['label'=>'Radius','type'=>\Elementor\Controls_Manager::DIMENSIONS,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__badge'=>'border-radius:{{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};']]);
49
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'meta_typo','selector'=>'{{WRAPPER}} .fresh-oo-property-header__badge']);
50
$this->end_controls_section();
51
$this->start_controls_section('style_price',['label'=>'Preis','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
52
$this->add_control('price_color',['label'=>'Preis','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__price-value'=>'color:{{VALUE}};']]);
53
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'price_typo','selector'=>'{{WRAPPER}} .fresh-oo-property-header__price-value']);
54
$this->add_control('price_label_color',['label'=>'Preisart','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__price-label'=>'color:{{VALUE}};']]);
55
$this->add_control('price_meta_color',['label'=>'Zusatztext','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-property-header__price-meta'=>'color:{{VALUE}};']]);
56
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'price_meta_typo','selector'=>'{{WRAPPER}} .fresh-oo-property-header__price-meta']);
57
$this->end_controls_section();
58
}
59
60
private function location(array $s): string {
61
$street=trim((string)$this->meta('oo_strasse')); $nr=trim((string)$this->meta('oo_hausnummer'));
62
$plz=trim((string)$this->meta('oo_plz')); $city=trim((string)$this->meta('oo_ort'));
63
return match($s['location_mode']??'city') {
64
'street' => trim(trim($street.' '.$nr).($street!=='' && ($plz!==''||$city!=='')?' · ':'').trim($plz.' '.$city)),
65
'postal' => trim($plz.' '.$city),
66
default => $city,
67
};
68
}
69
70
protected function render(): void {
71
$s=$this->get_settings_for_display();
72
$title=($s['title_source']??'post')==='field' ? trim((string)$this->meta('oo_objekttitel')) : get_the_title($this->current_post_id());
73
if($title==='') $title=trim((string)$this->meta('oo_objekttitel'));
74
$tag=in_array($s['title_tag']??'h1',['h1','h2','h3','div'],true)?$s['title_tag']:'h1';
75
$location=($s['show_location']??'yes')==='yes'?$this->location($s):'';
76
$badges=[];
77
if(($s['show_meta']??'yes')==='yes') {
78
foreach(['oo_objektart','oo_objekttyp','oo_vermarktungsart'] as $key){$v=$this->meta($key);if($this->meaningful_value($v,$key))$badges[]=$this->pretty_value($v,$key);}
79
if(($s['meta_show_year']??'')==='yes' && $this->meaningful_value($this->meta('oo_baujahr'),'oo_baujahr')) $badges[]='Baujahr '.$this->pretty_value($this->meta('oo_baujahr'),'oo_baujahr');
80
if(($s['meta_show_floor']??'')==='yes' && $this->meaningful_value($this->meta('oo_etage'),'oo_etage')) { $floor=$this->meta('oo_etage'); $badges[]='Etage '.(is_numeric($floor)?$this->format_number($floor,0,false):$this->pretty_value($floor,'oo_etage')); }
81
if(($s['meta_show_condition']??'')==='yes' && $this->meaningful_value($this->meta('oo_zustand'),'oo_zustand')) $badges[]=$this->pretty_value($this->meta('oo_zustand'),'oo_zustand');
82
}
83
if(($s['show_number']??'')==='yes' && $this->meaningful_value($this->meta('oo_objektnr_extern'))) $badges[]='Objekt '.trim((string)$this->meta('oo_objektnr_extern'));
84
$isRent=$this->is_rental();
85
$priceKey=$isRent?'oo_kaltmiete':'oo_kaufpreis'; $priceRaw=$this->meta($priceKey); $hasPrice=is_numeric($priceRaw)&&(float)$priceRaw>0;
86
$price=$hasPrice?$this->format_number($priceRaw).' €':trim((string)($s['price_on_request']??'Preis auf Anfrage'));
87
$secondary='';
88
if(($s['show_secondary']??'yes')==='yes'){
89
if($priceKey==='oo_kaltmiete' && $this->meaningful_value($this->meta('oo_warmmiete'),'oo_warmmiete',true)) $secondary='Warmmiete '.$this->format_number($this->meta('oo_warmmiete')).' €';
90
elseif($priceKey==='oo_kaufpreis' && $this->meaningful_value($this->meta('oo_hausgeld'),'oo_hausgeld',true)) $secondary='Hausgeld '.$this->format_number($this->meta('oo_hausgeld')).' € / Monat';
91
}
92
$commission=trim((string)$this->meta('oo_aussen_courtage'));
93
if($title==='' && $location==='' && !$badges && (($s['show_price']??'yes')!=='yes'||$price==='')){$this->editor_empty('Keine Daten für den Objektkopf vorhanden.');return;}
94
echo '<header class="fresh-oo-property-header">';
95
echo '<div class="fresh-oo-property-header__main"><div class="fresh-oo-property-header__content">';
96
if($title!=='') echo '<'.$tag.' class="fresh-oo-property-header__title">'.esc_html($title).'</'.$tag.'>';
97
if($location!=='') echo '<div class="fresh-oo-property-header__location">'.esc_html($location).'</div>';
98
if($badges){echo '<div class="fresh-oo-property-header__badges">';foreach($badges as $b)echo '<span class="fresh-oo-property-header__badge">'.esc_html($b).'</span>';echo '</div>';}
99
echo '</div>';
100
if(($s['show_price']??'yes')==='yes'&&$price!==''){
101
echo '<div class="fresh-oo-property-header__price"'.($hasPrice?' itemscope itemtype="https://schema.org/Offer"':'').'>';
102
echo '<span class="fresh-oo-property-header__price-label">'.esc_html($isRent?'Kaltmiete':'Kaufpreis').'</span>';
103
if($hasPrice){
104
echo '<span class="fresh-oo-property-header__price-value" itemprop="price" content="'.esc_attr((string)(float)$priceRaw).'">'.esc_html($price);
105
if($isRent && ($s['show_period']??'yes')==='yes') echo '<small> / Monat</small>';
106
echo '</span><meta itemprop="priceCurrency" content="EUR">';
107
} else echo '<span class="fresh-oo-property-header__price-value">'.esc_html($price).'</span>';
108
if($secondary!=='') echo '<span class="fresh-oo-property-header__price-meta">'.esc_html($secondary).'</span>';
109
if(($s['show_commission']??'yes')==='yes' && $commission!=='') echo '<span class="fresh-oo-property-header__price-meta">Provision: '.esc_html($commission).'</span>';
110
echo '</div>';
111
}
112
echo '</div></header>';
113
}
114
}
115
}
116