-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfc-widgets.php
701 lines (612 loc) · 27.6 KB
/
sfc-widgets.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
<?php
/*
* Activity Feed
*/
function get_sfc_activity_feed($args) {
$args = wp_parse_args($args, array(
'header'=>'true',
'site'=>'',
'bordercolor'=>'000000',
'width'=>'260',
'height'=>'400',
'font'=>'lucida+grande',
'colorscheme'=>'light',
'recommendations'=>'false'));
extract($args);
if ( empty($site) ) $site = home_url('/');
// handle parsing full url into domain and path for XFBML code
$url = parse_url($site);
if ( !empty( $url['host'] ) ) {
$host = $url['host'];
if ( !empty( $url['path'] ) && $url['path'] != '/' ) $path = "filter='{$url['path']}'";
else $path = '';
} else {
$host = $site;
$path = '';
}
return "<fb:activity site='{$host}' {$path} width='{$width}' height='{$height}' header='{$header}' colorscheme='{$colorscheme}' font='{$font}' border_color='{$bordercolor}' recommendations='{$recommendations}'></fb:activity>";
}
function sfc_activity_feed($args='') {
echo get_sfc_activity_feed($args);
}
function sfc_activity_feed_shortcode($atts) {
$args = shortcode_atts(array(
'header'=>'true',
'site'=>'',
'bordercolor'=>'000000',
'width'=>'260',
'height'=>'400',
'font'=>'lucida+grande',
'colorscheme'=>'light'), $atts);
return get_sfc_activity_feed($args);
}
add_shortcode('fb-activity', 'sfc_activity_feed_shortcode');
class SFC_Activity_Feed_Widget extends WP_Widget {
function SFC_Activity_Feed_Widget() {
$widget_ops = array('classname' => 'widget_sfc-activity-feed', 'description' => __('Facebook Activity Feed', 'sfc'));
$this->WP_Widget('sfc-activity', __('Facebook Activity Feed (SFC)', 'sfc'), $widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
sfc_activity_feed($instance);
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'width'=>260, 'height'=>400, 'bordercolor'=>'000000', 'font'=>'lucida+grande', 'colorscheme'=>'light') );
$instance['title'] = strip_tags($new_instance['title']);
$instance['width'] = intval($new_instance['width']);
$instance['height'] = intval($new_instance['height']);
$instance['bordercolor'] = strip_tags($new_instance['bordercolor']);
$instance['colorscheme'] = strip_tags($new_instance['colorscheme']);
$instance['font'] = strip_tags($new_instance['font']);
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'width'=>260, 'height'=>400, 'bordercolor'=>'000000', 'font'=>'lucida+grande', 'colorscheme'=>'light' ) );
$title = strip_tags($instance['title']);
$width = intval($instance['width']);
$height = intval($instance['height']);
$bordercolor = strip_tags($instance['bordercolor']);
if (empty($bordercolor)) $bordercolor = '000000';
$colorscheme = strip_tags($instance['colorscheme']);
$font = strip_tags($instance['font']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width of the widget in pixels:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo $width; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height of the widget in pixels:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo $height; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('bordercolor'); ?>"><?php _e('Border color:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('bordercolor'); ?>" name="<?php echo $this->get_field_name('bordercolor'); ?>" type="text" value="<?php echo $bordercolor; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('colorscheme'); ?>"><?php _e('Color scheme:', 'sfc'); ?>
<select name="<?php echo $this->get_field_name('colorscheme'); ?>" id="<?php echo $this->get_field_id('colorscheme'); ?>">
<option value="light" <?php selected('light', $colorscheme); ?>><?php _e('light', 'sfc'); ?></option>
<option value="dark" <?php selected('dark', $colorscheme); ?>><?php _e('dark', 'sfc'); ?></option>
</select>
</label></p>
<p><label for="<?php echo $this->get_field_id('font'); ?>"><?php _e('Font:', 'sfc'); ?>
<select name="<?php echo $this->get_field_name('font'); ?>" id="<?php echo $this->get_field_id('font'); ?>">
<option value="arial" <?php selected('arial', $font); ?>>arial</option>
<option value="lucide+grande" <?php selected('lucide+grande', $font); ?>>lucide grande</option>
<option value="segoe+ui" <?php selected('segoe+ui', $font); ?>>segoe ui</option>
<option value="tahoma" <?php selected('tahoma', $font); ?>>tahoma</option>
<option value="trebuchet+ms" <?php selected('trebuchet+ms', $font); ?>>trebuchet ms</option>
<option value="verdana" <?php selected('verdana', $font); ?>>verdana</option>
</select>
</label></p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("SFC_Activity_Feed_Widget");'));
/*
* Recommendations box
*/
function get_sfc_recommendations($args) {
$args = wp_parse_args($args, array(
'header'=>'true',
'site'=>'',
'bordercolor'=>'000000',
'width'=>'260',
'height'=>'400',
'font'=>'lucida+grande',
'colorscheme'=>'light',
'recommendations'=>'false'));
extract($args);
if (empty($site)) $site = home_url('/');
return "<fb:recommendations site='{$site}' width='{$width}' height='{$height}' header='{$header}' colorscheme='{$colorscheme}' font='{$font}' border_color='{$bordercolor}'></fb:recommendations>";
}
function sfc_recommendations($args='') {
echo get_sfc_recommendations($args);
}
function sfc_recommendations_shortcode($atts) {
$args = shortcode_atts(array(
'header'=>'true',
'site'=>'',
'bordercolor'=>'000000',
'width'=>'260',
'height'=>'400',
'font'=>'lucida+grande',
'colorscheme'=>'light'), $atts);
return get_sfc_recommendations($args);
}
add_shortcode('fb-recommend', 'sfc_recommendations_shortcode');
class SFC_Recommendations_Widget extends WP_Widget {
function SFC_Recommendations_Widget() {
$widget_ops = array('classname' => 'widget_sfc-recommendations', 'description' => __('Facebook Recommendations', 'sfc'));
$this->WP_Widget('sfc-recommendations', __('Facebook Recommendations (SFC)', 'sfc'), $widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
sfc_recommendations($instance);
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'width'=>260, 'height'=>400, 'bordercolor'=>'000000', 'font'=>'lucida+grande', 'colorscheme'=>'light') );
$instance['title'] = strip_tags($new_instance['title']);
$instance['width'] = intval($new_instance['width']);
$instance['height'] = intval($new_instance['height']);
$instance['bordercolor'] = strip_tags($new_instance['bordercolor']);
$instance['colorscheme'] = strip_tags($new_instance['colorscheme']);
$instance['font'] = strip_tags($new_instance['font']);
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'width'=>260, 'height'=>400, 'bordercolor'=>'000000', 'font'=>'lucida+grande', 'colorscheme'=>'light' ) );
$title = strip_tags($instance['title']);
$width = intval($instance['width']);
$height = intval($instance['height']);
$bordercolor = strip_tags($instance['bordercolor']);
if (empty($bordercolor)) $bordercolor = '000000';
$colorscheme = strip_tags($instance['colorscheme']);
$font = strip_tags($instance['font']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width of the widget in pixels:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo $width; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height of the widget in pixels:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo $height; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('bordercolor'); ?>"><?php _e('Border color:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('bordercolor'); ?>" name="<?php echo $this->get_field_name('bordercolor'); ?>" type="text" value="<?php echo $bordercolor; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('colorscheme'); ?>"><?php _e('Color scheme:', 'sfc'); ?>
<select name="<?php echo $this->get_field_name('colorscheme'); ?>" id="<?php echo $this->get_field_id('colorscheme'); ?>">
<option value="light" <?php selected('light', $colorscheme); ?>><?php _e('light', 'sfc'); ?></option>
<option value="dark" <?php selected('dark', $colorscheme); ?>><?php _e('dark', 'sfc'); ?></option>
</select>
</label></p>
<p><label for="<?php echo $this->get_field_id('font'); ?>"><?php _e('Font:', 'sfc'); ?>
<select name="<?php echo $this->get_field_name('font'); ?>" id="<?php echo $this->get_field_id('font'); ?>">
<option value="arial" <?php selected('arial', $font); ?>>arial</option>
<option value="lucide+grande" <?php selected('lucide+grande', $font); ?>>lucide grande</option>
<option value="segoe+ui" <?php selected('segoe+ui', $font); ?>>segoe ui</option>
<option value="tahoma" <?php selected('tahoma', $font); ?>>tahoma</option>
<option value="trebuchet+ms" <?php selected('trebuchet+ms', $font); ?>>trebuchet ms</option>
<option value="verdana" <?php selected('verdana', $font); ?>>verdana</option>
</select>
</label></p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("SFC_Recommendations_Widget");'));
/*
* Fan Box
*/
// fast check for sfc-fanbox-css request on plugin load
if (array_key_exists('sfc-fanbox-css', $_GET) && !empty($_GET['sfc-fanbox-css'])) {
$options = get_option('sfc_options');
header( 'Content-Type: text/css; charset=utf-8' );
echo $options['fanbox_css'];
exit; // stop normal WordPress execution
}
function get_sfc_fanbox($args='') {
$options = get_option('sfc_options');
$args = wp_parse_args($args, array(
'stream' => 1,
'connections' => 10,
'colorscheme' => 'light', // light or dark
'width' => 200,
'height' => 0,
'logobar' => 1
));
extract($args);
if ($options['fanpage']) $id = $options['fanpage'];
else $id = $options['appid'];
$retvar = '<fb:fan profile_id="'.$id.'" logobar="'.$logobar.'" stream="'.$stream.'" connections="'.$connections.'" width="'.$width.'" colorscheme="'.$colorscheme.'"';
if ($options['fanbox_css']) {
$retvar .= ' css="'.get_bloginfo('url').'/?sfc-fanbox-css='.$options['fanbox_time'].'"';
}
if ($height) $retvar .= ' height="'.$height.'"';
$retvar .= '></fb:fan>';
//<fb:like-box profile_id="185550966885" width="242" connections="9" stream="false" header="false"></fb:like-box>
return $retvar;
}
function sfc_fanbox($args='') {
echo get_sfc_fanbox($args);
}
// Shortcode for putting it into pages or posts directly
function sfc_fanbox_shortcode($atts) {
$args = shortcode_atts(array(
'stream' => 1,
'connections' => 10,
'colorscheme' => 'light', // light or dark
'width' => 200,
'height' => 0,
'logobar' => 1,
), $atts);
return get_sfc_fanbox($args);
}
add_shortcode('fb-fanbox', 'sfc_fanbox_shortcode');
class SFC_Fan_Box_Widget extends WP_Widget {
function SFC_Fan_Box_Widget() {
$widget_ops = array('classname' => 'widget_sfc-fanbox', 'description' => __('Facebook Fan Box', 'sfc'));
$this->WP_Widget('sfc-fanbox', __('Facebook Fan Box (SFC)', 'sfc'), $widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$instance['stream'] = isset($instance['stream']) ? $instance['stream'] : 1;
$instance['logobar'] = isset($instance['logobar']) ? $instance['logobar'] : 1;
$instance['connections'] = intval($instance['connections']);
$instance['width'] = intval($instance['width']);
$instance['height'] = intval($instance['height']);
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php sfc_fanbox($instance); ?>
<?php echo $after_widget; ?>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'connections' => '0', 'logobar'=> 0, 'stream' => 0, 'width'=>200, 'height'=>0) );
$instance['title'] = strip_tags($new_instance['title']);
$instance['connections'] = intval($new_instance['connections']);
$instance['width'] = intval($new_instance['width']);
$instance['height'] = intval($new_instance['height']);
$instance['stream'] = $new_instance['stream'] ? 1 : 0;
$instance['logobar'] = $new_instance['logobar'] ? 1 : 0;
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'connections' => '0', 'logobar'=> 0, 'stream' => 0, 'width'=>200, 'height'=>0) );
$title = strip_tags($instance['title']);
$connections = intval($instance['connections']);
$width = intval($instance['width']);
$height = intval($instance['height']);
$stream = $instance['stream'] ? true : false;
$logobar = $instance['logobar'] ? true : false;
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('logobar'); ?>"><?php _e('Show Facebook Logo Bar?', 'sfc'); ?>
<input class="checkbox" id="<?php echo $this->get_field_id('logobar'); ?>" name="<?php echo $this->get_field_name('logobar'); ?>" type="checkbox" <?php checked($logobar, true); ?> />
</label></p>
<p><label for="<?php echo $this->get_field_id('stream'); ?>"><?php _e('Show Stream Stories? ', 'sfc'); ?>
<input class="checkbox" id="<?php echo $this->get_field_id('stream'); ?>" name="<?php echo $this->get_field_name('stream'); ?>" type="checkbox" <?php checked($stream, true); ?> />
</label></p>
<p><label for="<?php echo $this->get_field_id('connections'); ?>"><?php _e('Number of Fans to Show:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('connections'); ?>" name="<?php echo $this->get_field_name('connections'); ?>" type="text" value="<?php echo $connections; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width of the widget in pixels:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo $width; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height of the widget in pixels (0 for automatic):', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo $height; ?>" />
</label></p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("SFC_Fan_Box_Widget");'));
// add the admin sections to the sfc page
add_action('admin_init', 'sfc_fanbox_admin_init');
function sfc_fanbox_admin_init() {
add_settings_section('sfc_fanbox', __('Fan Box Settings', 'sfc'), 'sfc_fanbox_section_callback', 'sfc');
add_settings_field('sfc_fanbox_css', __('Fanbox Custom CSS', 'sfc'), 'sfc_fanbox_css_callback', 'sfc', 'sfc_fanbox');
}
function sfc_fanbox_section_callback() {
echo '<p>'.__('Use this area to add any custom CSS you like to the Facebook Fan Box display.', 'sfc').'</p>';
}
function sfc_fanbox_css_callback() {
$options = get_option('sfc_options');
if (!isset($options['fanbox_css'])) $options['fanbox_css'] = '';
/* good default CSS to use:
.connect_widget .connect_widget_facebook_logo_menubar {
}
.fan_box .full_widget .connect_top {
}
.fan_box .full_widget .page_stream {
}
.fan_box .full_widget .connections {
}
*/
?>
<p><label><textarea name="sfc_options[fanbox_css]" class="large-text code" rows="10"><?php echo $options['fanbox_css']; ?></textarea></label></p>
<?php
}
add_filter('sfc_validate_options','sfc_fanbox_validate_options');
function sfc_fanbox_validate_options($input) {
$input['fanbox_css'] = strip_tags($input['fanbox_css']);
$input['fanbox_time'] = time();
return $input;
}
/*
* User Status
*/
class SFC_User_Status_Widget extends WP_Widget {
function SFC_User_Status_Widget() {
$widget_ops = array('classname' => 'widget_sfc-status', 'description' => __('Facebook User Status (needs user profile number)', 'sfc') );
$this->WP_Widget('sfc-userstatus', __('Facebook Status (SFC)', 'sfc'), $widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$statuses = get_transient($this->get_field_id('statuses'));
if ( $statuses === false || !empty( $statuses['error'] ) ) {
$statuses = sfc_remote($instance['profileid'], 'statuses', array('access_token'=>$instance['access_token']));
set_transient($this->get_field_id('statuses'), $statuses, 60*60); // 1 hour cache
}
if (!empty($statuses) && !empty($statuses['data'][0]['message']))
$status = "<a href='http://www.facebook.com/{$statuses['data'][0]['from']['id']}/posts/{$statuses['data'][0]['id']}'>{$statuses['data'][0]['message']}</a>";
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
echo $status;
echo $after_widget;
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
$profileid = esc_attr($instance['profileid']);
$access_token = esc_attr($instance['access_token']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('profileid'); ?>"><?php _e('Facebook User Profile Number:', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('profileid'); ?>" name="<?php echo $this->get_field_name('profileid'); ?>" type="text" value="<?php echo $profileid; ?>" />
</label></p>
<input class="widefat" id="<?php echo $this->get_field_id('access_token'); ?>" name="<?php echo $this->get_field_name('access_token'); ?>" type="hidden" value="<?php echo $access_token; ?>" />
<p><?php _e('You have to grant permissions for the widget to get your Status updates'); ?></p>
<fb:login-button v="2" scope="read_stream" onlogin="sfcUserStatusSetup('<?php echo 'widget-'.$this->id_base.'-'.$this->number; ?>')">Grant Permissions</fb:login-button>
<script type="text/javascript">
// Refresh the DOM
FB.XFBML.parse();
</script>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("SFC_User_Status_Widget");'));
add_action('admin_footer-widgets.php','sfc_userstatus_widget_script');
function sfc_userstatus_widget_script() {
?>
<script type="text/javascript">
function sfcUserStatusSetup(base) {
FB.getLoginStatus(function(response) {
if (response.authResponse) {
jQuery('#'+base+'-profileid').val(response.authResponse.userID);
jQuery('#'+base+'-access_token').val(response.authResponse.accessToken);
} else {
jQuery('#'+base+'-profileid').val('');
jQuery('#'+base+'-access_token').val('');
}
});
}
</script>
<?php
}
/**
* Chicklet
*/
define('SFC_FANCOUNT_CACHE',60*60); // 1 hour caching
// checks for sfc on activation
function sfc_chicklet($id = 0) {
$options = get_option('sfc_options');
if ($id == 0) {
if ($options['fanpage']) $id = $options['fanpage'];
else $id = $options['appid'];
}
$sfc_chicklet_fancount = get_transient('sfc_chicklet_fancount');
if (!isset($sfc_chicklet_fancount[$id])) {
$data = wp_remote_get("http://api.facebook.com/method/fql.query?format=json&query=select+page_url,fan_count+from+page+where+page_id={$id}");
if (!is_wp_error($data)) {
$resp = json_decode($data['body'],true);
if (!empty($resp)) {
$sfc_chicklet_fancount[$id] = array_shift($resp);
set_transient('sfc_chicklet_fancount',$sfc_chicklet_fancount,SFC_FANCOUNT_CACHE);
}
}
}
if (!empty($sfc_chicklet_fancount[$id])) {
$fancount = $sfc_chicklet_fancount[$id]['fan_count'];
$pageurl = $sfc_chicklet_fancount[$id]['page_url'];
}
global $sfc_chicklet_no_style;
if (!$sfc_chicklet_no_style) {
?>
<style>
.fanBoxChicklet {
width:88px;
height:17px;
overflow:auto;
background-color:#94bfbf;
border-top: 1px solid #cefdfd;
border-left: 1px solid #cefdfd;
border-right: 1px solid #5f8586;
border-bottom: 1px solid #5f8586;
font: 11px/normal monospace, courier new, sans-serif;
color:#59564f;
margin: 0;
padding: 0;
text-align:right;
}
.fanBoxChicklet .quantity {
width:auto;
height:13px;
min-width:40px;
background-color:#cefdfd;
border-top: 1px solid #8a8a8a;
border-left: 1px solid #8a8a8a;
border-right: 1px solid #fefffe;
border-bottom: 1px solid #fefffe;
padding: 2px;
float: left;
text-align: center;
overflow: hidden;
margin:1px 5px 0 0;
padding:0;
}
.fanBoxChicklet .readerCaption {
width:auto;
float: left;
text-align: center;
vertical-align: middle;
margin: 2px 0 0 0;
padding: 0;
}
.fanBoxChicklet .feedCountLink {
color:#59564f;
text-decoration:none;
margin:0;
padding:0;
}
.fanBoxBy {
width:88px;
height:9px;
font: 9px/normal monospace, courier new, sans-serif;
color:#59564f;
}
</style>
<?php } ?>
<div class="fanBoxChicklet fanBoxChicklet-<?php echo $id; ?>">
<p class="quantity"><?php echo $fancount; ?></p>
<p class="readerCaption"><a href="<?php echo $pageurl; ?>" class="feedCountLink" target="_blank"><?php _e('Fans', 'sfc'); ?></a></p>
</div>
<div class="fanBoxBy"><?php _e('ON FACEBOOK', 'sfc'); ?></div>
<?php
}
class SFC_Chicklet_Widget extends WP_Widget {
function SFC_Chicklet_Widget() {
$widget_ops = array('classname' => 'widget_sfc-chicklet', 'description' => __('Facebook Chicklet', 'sfc'));
$this->WP_Widget('sfc-chicklet', __('Facebook Chicklet (SFC)', 'sfc'), $widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php sfc_chicklet(); ?>
<?php echo $after_widget; ?>
<?php
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label></p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("SFC_Chicklet_Widget");'));
/**
* Live Stream Widget
*/
function get_sfc_livestream($args='') {
$options = get_option('sfc_options');
$args = wp_parse_args($args, array(
'width' => '200',
'height' => '400',
'xid' => '',
'always_post_to_friends'=>'false',
'event_app_id' => $options['appid'],
));
extract($args);
return "<fb:live-stream event_app_id='{$event_app_id}' width='{$width}' height='{$height}' xid='{$xid}' always_post_to_friends='{$always_post_to_friends}'></fb:live-stream>";
}
function sfc_livestream($args='') {
echo get_sfc_livestream($args);
}
function sfc_live_stream_shortcode($atts) {
$options = get_option('sfc_options');
$args = shortcode_atts(array(
'width' => '200',
'height' => '400',
'xid' => '',
'always_post_to_friends'=>'false',
'event_app_id' => $options['appid'],
), $atts);
return get_sfc_livestream($args);
}
add_shortcode('fb-livestream', 'sfc_live_stream_shortcode');
class SFC_Live_Stream_Widget extends WP_Widget {
function SFC_Live_Stream_Widget() {
$widget_ops = array('classname' => 'widget_sfc-livestream', 'description' => __('Facebook Live Stream', 'sfc'));
$this->WP_Widget('sfc-livestream', __('Facebook Live Stream (SFC)', 'sfc'), $widget_ops);
}
function widget($args, $instance) {
$options = get_option('sfc_options');
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$width = intval($instance['width']);
$height = intval($instance['height']);
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php sfc_livestream($instance); ?>
<?php echo $after_widget; ?>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'width'=>200, 'height'=>400 ) );
$instance['title'] = strip_tags($new_instance['title']);
$instance['width'] = intval($new_instance['width']);
if ($instance['width'] < 200) $instance['width'] = 200;
$instance['height'] = intval($new_instance['height']);
if ($instance['height'] < 400) $instance['height'] = 400;
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'width'=>200, 'height'=>400 ) );
$title = strip_tags($instance['title']);
$width = intval($instance['width']);
$height = intval($instance['height']);
$stream = $instance['stream'] ? true : false;
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width of the widget in pixels (minimum 200):', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo $width; ?>" />
</label></p>
<p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height of the widget in pixels (minimum 400):', 'sfc'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo $height; ?>" />
</label></p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("SFC_Live_Stream_Widget");'));