This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
/
follow-button.php
205 lines (174 loc) · 5.95 KB
/
follow-button.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* Adds the Follow Button Social Plugin as a WordPress Widget
*
* @since 1.0
*/
class Facebook_Follow_Button_Widget extends WP_Widget {
/**
* Register widget with WordPress
*
* @since 1.0
*
* @return void
*/
public function __construct() {
parent::__construct(
'facebook-follow', // Base ID
__( 'Facebook Follow Button', 'facebook' ), // Name
array( 'description' => __( 'Lets a user follow your public updates on Facebook.', 'facebook' ) ) // Args
);
}
/**
* Front-end display of widget.
*
* @since 1.0
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
* @return void
*/
public function widget( $args, $instance ) {
// no follow target. fail early
if ( empty( $instance['href'] ) )
return;
extract( $args );
if ( ! isset( $instance['ref'] ) )
$instance['ref'] = 'widget';
if ( ! function_exists( 'facebook_get_follow_button' ) )
require_once( dirname( dirname(__FILE__) ) . '/social-plugins.php' );
$follow_button_html = facebook_get_follow_button( $instance );
if ( ! ( is_string( $follow_button_html ) && $follow_button_html ) )
return;
echo $before_widget;
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
if ( $title )
echo $before_title . $title . $after_title;
echo $follow_button_html;
echo $after_widget;
}
/**
* Sanitize widget form values as they are saved.
*
* @since 1.0
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$new_instance = (array) $new_instance;
if ( ! empty( $new_instance['title'] ) )
$instance['title'] = strip_tags( $new_instance['title'] );
if ( isset( $new_instance['show_faces'] ) )
$new_instance['show_faces'] = true;
else
$new_instance['show_faces'] = false;
if ( isset( $new_instance['width'] ) )
$new_instance['width'] = absint( $new_instance['width'] );
if ( ! class_exists( 'Facebook_Follow_Button' ) )
require_once( dirname( dirname(__FILE__) ) . '/class-facebook-follow-button.php' );
$follow_button = Facebook_Follow_Button::fromArray( $new_instance );
if ( $follow_button ) {
if ( ! class_exists( 'Facebook_Follow_Button_Settings' ) )
require_once( dirname( dirname( dirname(__FILE__) ) ) . '/admin/settings-follow-button.php' );
return array_merge( $instance, Facebook_Follow_Button_Settings::html_data_to_options( $follow_button->toHTMLDataArray() ) );
}
return $instance;
}
/**
* Back-end widget form.
*
* @since 1.0
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
* @return void
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'href' => '',
'layout' => 'standard',
'show_faces' => false,
'colorscheme' => 'light',
'font' => '',
'width' => 0
) );
$this->display_title( isset( $instance['title'] ) ? $instance['title'] : '' );
$this->display_href( isset( $instance['href'] ) ? $instance['href'] : '' );
if ( ! class_exists( 'Facebook_Follow_Button_Settings' ) )
require_once( dirname( dirname( dirname(__FILE__) ) ) . '/admin/settings-follow-button.php' );
$follow_button_settings = new Facebook_Follow_Button_Settings( $instance );
echo '<div>' . esc_html( __( 'Layout', 'facebook' ) ) . ': ';
$follow_button_settings->display_layout( array(
'id' => $this->get_field_id( 'layout' ),
'name' => $this->get_field_name( 'layout' )
) );
echo '</div><p></p>';
echo '<div>';
$follow_button_settings->display_show_faces( array(
'id' => $this->get_field_id( 'show_faces' ),
'name' => $this->get_field_name( 'show_faces' )
) );
echo '</div><p></p>';
echo '<div><label for="' . $this->get_field_id( 'width' ) . '">' . esc_html( __( 'Width', 'facebook' ) ) . '</label>: ';
$follow_button_settings->display_width( array(
'id' => $this->get_field_id( 'width' ),
'name' => $this->get_field_name( 'width' )
) );
echo '</div><p></p>';
echo '<div><label for="' . $this->get_field_id( 'font' ) . '">' . esc_html( __( 'Font', 'facebook' ) ) . '</label>: ';
$follow_button_settings->display_font( array(
'id' => $this->get_field_id( 'font' ),
'name' => $this->get_field_name( 'font' )
) );
echo '</div><p></p>';
echo '<div style="line-height:2em">' . esc_html( __( 'Color scheme', 'facebook' ) ) . ': ';
$follow_button_settings->display_colorscheme( array(
'id' => $this->get_field_id( 'colorscheme' ),
'name' => $this->get_field_name( 'colorscheme' )
) );
echo '</div>';
}
/**
* Allow a publisher to customize the title displayed above the widget area
*
* e.g. Like us on Facebook!
*
* @since 1.1
*
* @param string $existing_value saved title
* @return void
*/
public function display_title( $existing_value = '' ) {
echo '<p><label>' . esc_html( __( 'Title', 'facebook' ) ) . ': ';
echo '<input type="text" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" class="widefat"';
if ( $existing_value )
echo ' value="' . esc_attr( $existing_value ) . '"';
echo ' /></label></p>';
}
/**
* Customize the Like target
*
* @since 1.1
*
* @param string $existing_value stored URL value
* @return void
*/
public function display_href( $existing_value = '' ) {
echo '<p><label>URL: <input type="url" id="' . $this->get_field_id( 'href' ) . '" name="' . $this->get_field_name( 'href' ) . '" class="widefat" required';
if ( $existing_value )
echo ' value="' . esc_url( $existing_value, array( 'http', 'https' ) ) . '"';
echo ' /></label></p>';
echo '<p class="description">' . esc_html( __( 'Must be a Facebook URL', 'facebook' ) ) . '</p>';
}
}
?>