em-event-location-url.php
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace EM_Event_Locations;
/**
* Adds a URL event location type by extending EM_Event_Location and registering itself with EM_Event_Locations
*
* @property string url The url of this event location.
* @property string text The text used in a link for the url.
*/
class URL extends Event_Location {
public static $type = 'url';
public static $admin_template = '/forms/event/event-locations/url.php';
public $properties = array('url', 'text');
public function get_post(){
$return = parent::get_post();
if( !empty($_POST['event_location_url']) ){
$this->data['url'] = esc_url_raw($_POST['event_location_url']);
}
if( !empty($_POST['event_location_url_text']) ){
$this->data['text'] = sanitize_text_field($_POST['event_location_url_text']);
}
return apply_filters('em_event_location_url_get_post', $return, $this);
}
public function validate(){
$result = parent::validate();
if( empty($this->data['url']) ){
$this->event->add_error( __('Please enter a valid URL for this event location.', 'events-manager') );
$result = false;
}
if( empty($this->data['text']) ){
$this->event->add_error( __('Please provide some link text for this event location URL.', 'events-manager') );
$result = false;
}
return apply_filters('em_event_location_url_validate', $result, $this);
}
public function get_link( $new_target = true ){
return '<a href="'.esc_url($this->url).'">'. esc_html($this->text).'</a>';
}
public function get_admin_column() {
return '<strong>'. static::get_label() . ' - ' . $this->get_link().'</strong>';
}
public static function get_label( $label_type = 'singular' ){
switch( $label_type ){
case 'plural':
return esc_html__('URLs', 'events-manager');
break;
case 'singular':
return esc_html__('URL', 'events-manager');
break;
}
return parent::get_label($label_type);
}
public function output( $what = null, $target = null ){
if( $what === null ){
return '<a href="'. esc_url($this->url) .'" target="_blank">'. esc_html($this->text) .'</a>';
}elseif( $what === '_self' ){
return '<a href="'. esc_url($this->url) .'">'. esc_html($this->text) .'</a>';
}elseif( $what === '_parent' || $what === '_top' ){
return '<a href="'. esc_url($this->url) .'" target="'.$what.'">'. esc_html($this->text) .'</a>';
}else{
return parent::output($what);
}
}
public function get_ical_location(){
return $this->url;
}
}
URL::init();