forked from joeyblake/fatpanda-facebook-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
344 lines (302 loc) · 16.1 KB
/
settings.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<style>
.wrap h2 span { position: relative; font-size: 0.75em; padding-left: 20px; }
ul.ui-menu { background-color: #efefef; width: 300px; }
ul.ui-menu > li { padding: 4px 8px 0; cursor: pointer; }
ul.ui-menu > li:last-child { padding-bottom: 4px; }
.form-table { width: auto; }
.ad { position: absolute; top: 15px; right: 20px; border: 1px solid #ccc; padding: 4px; width:300px; }
@media (max-width: 1024px) {
.ad { width: 200px; }
.ad img { width: 200px; }
}
</style>
<?php if (get_option($this->id('imported_settings', false))) { ?>
<div class="updated">
<p>We <b>imported settings</b> from your other plugins. Make sure to look everything over closely!</p>
</div>
<?php } ?>
<div class="wrap">
<div id="icon-general" class="icon32" style="background:url('<?php echo plugins_url('icon32.png', __FILE__) ?>') no-repeat;"><br /></div>
<h2>
Facebook Comments
<span>a plugin from <a href="http://fatpandadev.com" target="_blank">Fat Panda</a></span>
</h2>
<a target="_blank" class="ad" href="http://aaroncollegeman.com/sharepress/?utm_source=facebook-comments-plugin&utm_medium=in-app-promo&utm_campaign=sharepress-sleep-more">
<img style="display:block;" src="<?php echo plugins_url('sharepress-ad.png', __FILE__) ?>" />
</a>
<form action="<?php echo admin_url('options.php') ?>" method="post" style="float:left;">
<?php settings_fields( get_class($this) ) ?>
<br />
<h3 class="title" style="margin-top:0;">Use Facebook Comments for commenting on your site?</h3>
<table class="form-table">
<tr>
<td>
<div style="margin-bottom:5px;">
<label>
<input type="radio" name="<?php $this->field('comments_enabled') ?>" value="on" <?php if ($this->is_enabled()) echo 'checked="checked"' ?> />
Yes, replace built-in commenting with the <a href="http://developers.facebook.com/docs/reference/plugins/comments/" target="_blank">Facebook Comments widget</a>.
</label>
</div>
<div>
<label>
<input type="radio" name="<?php $this->field('comments_enabled') ?>" value="off" <?php if (!$this->is_enabled()) echo 'checked="checked"' ?> />
No, please disable this plugin.
</label>
</div>
</td>
</tr>
</table>
<br />
<h3 class="title">Who are your moderators?</h3>
<?php if ($app_id) { ?>
<div id="<?php $this->id('moderator-picker') ?>" style="display:none;">
<p class="description">You can set moderators on a post-by-post and page-by-page basis. Set your global defaults below.</p>
<table class="form-table">
<tr>
<td>
<div style="margin-bottom: 5px;">
<label style="float:left; margin-top:3px;">
<input type="checkbox" name="<?php $this->field('app_moderator_mode') ?>" value="on" <?php $this->checked($this->setting('app_moderator_mode', 'on') == 'on') ?> />
The administrators of my <a href="http://developers.facebook.com/docs/appsonfacebook/tutorial/" target="_blank">Facebook Application</a> are moderators
</label>
<span style="margin-left:25px;">
<label for="<?php $this->id('app_id') ?>">
App ID:
</label>
<input type="text" class="regular-text" id="<?php $this->id('app_id') ?>" style="width:12em;" name="<?php $this->field('app_id') ?>" value="<?php echo esc_attr($app_id) ?>" />
</span>
<div style="clear:both;"></div>
</div>
<div id="<?php $this->id('connected') ?>">
<div>
<label>
<input type="checkbox" name="<?php $this->field('admin_moderator_mode') ?>" value="on" <?php $this->checked($this->setting('admin_moderator_mode', 'on') == 'on') ?> />
These Facebook people are also my moderators:
</label>
</div>
<p>
<ul id="<?php $this->id('moderators') ?>">
<?php foreach(array_unique($this->setting('moderators', array())) as $moderator) { ?>
<li><input type="hidden" name="<?php $this->field('moderators[]') ?>" value="<?php echo $moderator ?>" /> <span rel="<?php echo $moderator ?>"><?php echo $moderator ?></span> <a href="#" onclick="remove_moderator(this); return false;">remove</a></li>
<?php } ?>
</ul>
<div id="<?php $this->id('finder') ?>" style="display:none;">
<label for="<?php $this->id('add_another_friend') ?>">Search by name:</label>
<input id="<?php $this->id('add_another_friend') ?>" type="text" name="add_another_friend" class="regular-text" />
<span id="<?php $this->id('searching') ?>" style="display:none;">Searching...</span>
<a id="<?php $this->id('add-moderator') ?>" class="button" onclick="add_moderator(this); return false;" style="display:none;">Add Moderator</a>
</div>
<script>
(function($) {
$(function() {
/*
* jQuery UI Autocomplete HTML Extension
*
* Copyright 2010, Scott González (http://scottgonzalez.com)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* http://github.com/scottgonzalez/jquery-ui-extensions
*/
var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
function filter( array, term ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
return $.grep( array, function(value) {
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
});
}
$.extend( proto, {
_initSource: function() {
if ( this.options.html && $.isArray(this.options.source) ) {
this.source = function( request, response ) {
response( filter( this.options.source, request.term ) );
};
} else {
initSource.call( this );
}
},
_renderItem: function( ul, item) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( $( "<a></a>" ).addClass(item.value == null ? 'null-item' : '')[ this.options.html ? "html" : "text" ]( item.label ) )
.appendTo( ul );
}
});
$('#<?php $this->id('add_another_friend') ?>').autocomplete({
html: true,
source: function(request, response) {
$('#<?php $this->id('searching') ?>').show();
$('#<?php $this->id('add-moderator') ?>').hide();
FB.api('/search?q='+encodeURI(request.term)+'&type=user&limit=10', function(R) {
$('#<?php $this->id('searching') ?>').hide();
response($.map(R.data, function(user) {
return {
label: '<img width="24" height="24" src="http://graph.facebook.com/'+user.id+'/picture?size=square" align="absmiddle" /> '+user.name,
value: user.id
}
}));
});
},
focus: false,
select: function(ui, e) {
$('#<?php $this->id('add-moderator') ?>').show();
console.log(arguments);
}
});
$('#<?php $this->id('finder') ?>').show();
});
})(jQuery);
</script>
</p>
</div>
</td>
</tr>
</table>
</div>
<div id="<?php $this->id('facebook-login') ?>">
<a class="button-primary" onclick="FB.login(); return false;">Login to Facebook</a>
<a class="button" href="<?php echo admin_url('?action=fatpanda-facebook-comments-reset-app') ?>">Change App ID</a>
</div>
<div id="fb-root"></div>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '<?php echo $app_id ?>'
});
(function($) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
revealModeration();
} else {
// Subscribe to the event 'auth.authResponseChange' and wait for the user to autenticate
FB.Event.subscribe('auth.authResponseChange', function(response) {
// nothing more needed than to reload the page
if (response.status === 'connected') {
revealModeration();
}
},true);
$('#<?php $this->id('facebook-login') ?>').show();
}
});
function revealModeration() {
$('#<?php $this->id('moderator-picker') ?>').show();
$('#<?php $this->id('facebook-login') ?>').hide();
var batch = $.map($('#<?php $this->id('moderators') ?> li span'), function(span, i) {
return { method: 'GET', relative_url: $(span).attr('rel') };
});
FB.api('/', 'POST', {
'batch': batch
}, function(response) {
for (i in response) {
var user = eval('('+response[i].body+')');
$('span[rel="'+user.id+'"]').html('<img width="24" src="http://graph.facebook.com/'+user.id+'/picture?size=square" align="absmiddle" /> <a href="http://facebook.com/profile.php?id='+user.id+'" target="_blank">'+user.name+'</a>');
}
});
}
window.remove_moderator = function(a) {
$(a).closest('li').remove();
}
window.add_moderator = function(a) {
$('#<?php $this->id('add-moderator') ?>').hide();
var $moderator = $('#<?php $this->id('add_another_friend') ?>');
var $list = $('#<?php $this->id('moderators') ?>');
var id = $moderator.val();
$moderator.val('');
var $placeholder = $('<li>Loading...</li>');
$list.append($placeholder);
FB.api(id, function(user) {
$placeholder.replaceWith('<li><input type="hidden" name="<?php $this->field('moderators[]') ?>" value="'+user.id+'" /><img width="24" src="http://graph.facebook.com/'+user.id+'/picture?size=square" align="absmiddle" /> <a href="http://facebook.com/profile.php?id='+user.id+'" target="_blank">'+user.name+'</a> <a href="#" onclick="remove_moderator(this); return false;">remove</a></li>');
});
}
})(jQuery);
</script>
<?php } else { ?>
<input type="hidden" name="<?php $this->field('app_moderator_mode') ?>" value="<?php echo esc_attr($this->setting('app_moderator_mode', 'on')) ?>" />
<input type="hidden" name="<?php $this->field('admin_moderator_mode') ?>" value="<?php echo esc_attr($this->setting('admin_moderator_mode', 'on')) ?>" />
<?php foreach($this->setting('moderators', array()) as $id) { ?>
<input type="hidden" name="<?php $this->field('moderators[]') ?>" value="<?php echo esc_attr($id) ?>" />
<?php } ?>
<p>To setup Moderation, enter your <a href="http://developers.facebook.com/docs/appsonfacebook/tutorial/" target="_blank">Facebook Application ID</a> below.</p>
<table class="form-table">
<tr>
<th>
<label for="<?php $this->id('app_id') ?>">App ID:</label>
</th>
<td>
<input type="text" name="<?php $this->field('app_id') ?>" value="<?php echo esc_attr($this->setting('app_id')) ?>" class="regular-text" />
<input type="submit" class="button-primary" value="Save" />
</td>
</tr>
</table>
<?php } ?>
<input type="hidden" name="<?php $this->field('xid') ?>" value="<?php esc_attr($xid) ?>" />
<input type="hidden" name="<?php $this->field('support_xid') ?>" value="<?php echo $this->should_support_xid() ? 'on' : 'off' ?>" />
<br />
<h3 class="title">Display the non-facebook comments that are in your database?</h3>
<table class="form-table">
<tr>
<td>
<div style="margin-bottom:5px;">
<label>
<input type="radio" name="<?php $this->field('show_old_comments') ?>" value="on" <?php if ($this->setting('show_old_comments', 'on') == 'on') echo 'checked="checked"' ?> />
Yes, because I've got a lot of historical comments in there!
</label>
</div>
<div>
<label>
<input type="radio" name="<?php $this->field('show_old_comments') ?>" value="off" <?php if ($this->setting('show_old_comments', 'on') == 'off') echo 'checked="checked"' ?> />
No, not necessary, but hide them in a <code><noscript></code> tag to maximize SEO.
</label>
</div>
</td>
</tr>
</table>
<br />
<h3 class="title">Display Settings</h3>
<table class="form-table">
<tr>
<th>
<label for="<?php $this->id('num_posts') ?>">Number of posts</label>
</th>
<td>
<input type="text" class="regular-text" style="width:5em;" id="<?php $this->id('num_posts') ?>" name="<?php $this->field('num_posts') ?>" value="<?php echo esc_attr($this->get_num_posts()) ?>" />
<span class="description">The number of posts to display by default</span>
</td>
</tr>
<tr>
<th>
<label for="<?php $this->id('width') ?>">Width</label>
</th>
<td>
<input type="text" class="regular-text" style="width:5em;" id="<?php $this->id('width') ?>" name="<?php $this->field('width') ?>" value="<?php echo esc_attr($this->get_width()) ?>" />
<span class="description">The width of the widget, in pixels (e.g., "100") or percentage (e.g., "100%")</span>
</td>
</tr>
<tr>
<th>
<label for="<?php $this->id('colorscheme') ?>">Color Scheme</label>
</th>
<td>
<select id="<?php $this->id('colorscheme') ?>" name="<?php $this->field('colorscheme') ?>">
<?php foreach(array('light', 'dark') as $scheme) { ?>
<option value="<?php echo $scheme ?>" <?php $this->selected($scheme === $this->setting('colorscheme', 'light')) ?>><?php echo $scheme ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<th>
<label for="<?php $this->id('comment_form_title') ?>">Form Title</label>
</th>
<td>
<input type="text" class="regular-text" id="<?php $this->id('comment_form_title') ?>" name="<?php $this->field('comment_form_title') ?>" value="<?php echo esc_attr($this->setting('comment_form_title', '')) ?>" />
<br /><span class="description">Just in case you need to add a title above your comment form, e.g., <h3>Comments</h3></span>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php esc_attr_e('Save All Changes'); ?>" />
</p>
</form>
<div style="clear:both;"></div>
</div>