This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 235
/
fb-comments.php
181 lines (149 loc) · 7.24 KB
/
fb-comments.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
<?php
function fb_insights_page() {
$options = get_option('fb_options');
if (!empty($options["app_id"])) {
echo '<script>window.location = ' . json_encode( 'https://www.facebook.com/insights/?' . http_build_query( array( 'sk' => 'ao_' . $options['app_id'] ) ) ) . ';</script>';
}
}
function fb_hide_wp_comments() {
wp_enqueue_style( 'fb_hide_wp_comments', plugins_url( 'style/hide-wp-comments.css', dirname(__FILE__)), array(), '1.0' );
}
function fb_hide_wp_comments_homepage() {
return '';
}
function fb_set_wp_comment_status ( $posts ) {
if ( ! empty( $posts ) && is_singular() ) {
$posts[0]->comment_status = 'open';
$posts[0]->post_status = 'open';
}
return $posts;
}
function fb_close_wp_comments($comments) {
return null;
}
function fb_get_comments($options = array()) {
if (isset($options['href']) == '') {
$options['href'] = get_permalink();
}
$params = fb_build_social_plugin_params($options);
$output = fb_get_fb_comments_seo();
$output .= '<div class="fb-comments fb-social-plugin" ' . $params . '></div>';
return $output;
}
function fb_get_comments_count() {
return '<iframe src="' . ( is_ssl() ? 'https' : 'http' ) . '://www.facebook.com/plugins/comments.php?' . http_build_query( array( 'href' => get_permalink(), 'permalink' => 1 ) ) . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:16px;" allowTransparency="true"></iframe>';
}
function fb_comments_automatic($content) {
global $post;
if ( isset ( $post ) ) {
if ( comments_open( get_the_ID() ) && post_type_supports( get_post_type(), 'comments' ) ) {
$options = get_option('fb_options');
$show_indiv = get_post_meta( $post->ID, 'fb_social_plugin_settings_box_comments', true );
if ( ! is_home() && ( 'default' == $show_indiv || empty( $show_indiv ) ) && isset( $options['comments']['show_on'] ) ) {
if ( ( is_page() && ( $options['comments']['show_on'] == 'all pages' || $options['comments']['show_on'] == 'all posts and pages' ) )
or ( is_single() && ( $options['comments']['show_on'] == 'all posts' || $options['comments']['show_on'] == 'all posts and pages' ) ) )
{
foreach( $options['comments'] as $param => $val ) {
$param = str_replace( '_', '-', $param );
$params[$param] = $val;
}
$content .= fb_get_comments( $params );
}
}
elseif ( 'show' == $show_indiv || ( ( ! isset( $options['comments']['show_on'] ) ) && ( 'default' == $show_indiv || empty( $show_indiv ) ) ) ) {
foreach( $options['comments'] as $param => $val ) {
$param = str_replace( '_', '-', $param );
$params[$param] = $val;
}
$content .= fb_get_comments( $params );
}
//elseif ( 'no' == $show_indiv ) {
//}
}
}
return $content;
}
function fb_get_fb_comments_seo() {
global $facebook;
global $post;
if ( isset( $post ) ) {
$url = get_permalink();
if ( false === ( $comments = get_transient( 'fb_comments_' . $post->ID ) ) ) {
try {
$comments = $facebook->api('/comments', array('ids' => $url));
}
catch (WP_FacebookApiException $e) {
}
set_transient( 'fb_comments_' . $post->ID, $comments, 60*15 );
}
if ( ! isset( $comments[$url] ) )
return '';
$output = '<noscript><ol class="commentlist">';
foreach ($comments[$url]['comments']['data'] as $key => $comment_info) {
$unix_timestamp = strtotime($comment_info['created_time']);
$output .= '<li id="' . esc_attr( 'comment-' . $key ) . '">
<p><a href="' . esc_url( 'http://www.facebook.com/' . $comment_info['from']['id'], array( 'http', 'https' ) ) . '">' . esc_html( $comment_info['from']['name'] ) . '</a>:</p>
<p class="metadata">' . date('F jS, Y', $unix_timestamp) . ' at ' . date('g:i a', $unix_timestamp) . '</p>
' . $comment_info['message'] . '
</li>';
if (isset($comment_info['comments']) && isset($comment_info['comments']['data'])) {
foreach ($comment_info['comments']['data'] as $second_key => $comment_info) {
$unix_timestamp = strtotime($comment_info['created_time']);
$output .= '<li id="' . esc_attr( 'comment-' . $key . '-' . $second_key ) . '">
<p><a href="' . esc_url( 'http://www.facebook.com/' . $comment_info['from']['id'], array( 'http', 'https' ) ) . '">' . esc_html( $comment_info['from']['name'] ) . '</a>:</p>
<p class="metadata">' . date('F jS, Y', $unix_timestamp) . ' at ' . date('g:i a', $unix_timestamp) . '</p>
' . $comment_info['message'] . '
</li>';
}
}
}
$output .= '</ol></noscript>';
}
return $output;
}
function fb_get_comments_fields($placement = 'settings', $object = null) {
$fields_array = fb_get_comments_fields_array();
fb_construct_fields($placement, $fields_array['children'], $fields_array['parent'], $object);
}
function fb_get_comments_fields_array() {
$array['parent'] = array('name' => 'comments',
'type' => 'checkbox',
'label' => 'Comments',
'description' => 'The Comments Box is a social plugin that enables user commenting on your site. Features include moderation tools and distribution.',
'help_link' => 'https://developers.facebook.com/docs/reference/plugins/comments/',
'image' => plugins_url( '/images/settings_comments.png', dirname(__FILE__))
);
$array['children'] = array(array('name' => 'num_posts',
'label' => 'Number of posts',
'type' => 'text',
'default' => 20,
'help_text' => 'The number of posts to display by default.',
),
array('name' => 'width',
'type' => 'text',
'default' => '470',
'help_text' => 'The width of the plugin, in pixels.',
),
array('name' => 'colorscheme',
'label' => 'Color scheme',
'type' => 'dropdown',
'default' => 'light',
'options' => array('light' => 'light', 'dark' => 'dark'),
'help_text' => 'The color scheme of the plugin.',
),
array('name' => 'show_on',
'type' => 'dropdown',
'default' => 'all posts and pages',
'options' => array('all posts' => 'all posts', 'all pages' => 'all pages', 'all posts and pages' => 'all posts and pages', 'individual posts and pages' => 'individual posts and pages' ),
'help_text' => __( 'Whether the plugin will appear on all posts or pages by default. If "individual posts and pages" is selected, you must explicitly set each post and page to display the plugin.', 'facebook' ),
),
array('name' => 'homepage_comments',
'label' => 'Show comment counts on the homepage',
'type' => 'checkbox',
'default' => 'true',
'help_text' => __('Whether the plugin will display a comment count for each post on the homepage.'),
)
);
return $array;
}
?>