WP Embed Facebook - Version 1.9.6.6

Version Description

  • Fixed Embed Video Error
  • Fixed like and follow button html
Download this release

Release Info

Developer poxtron
Plugin Icon 128x128 WP Embed Facebook
Version 1.9.6.6
Comparing to
See all releases

Code changes from version 1.9.6.5 to 1.9.6.6

Files changed (3) hide show
  1. lib/core.php +277 -289
  2. readme.txt +7 -3
  3. wp-embed-facebook.php +1 -1
lib/core.php CHANGED
@@ -9,43 +9,43 @@ class WP_Embed_FB {
9
  static $height = '';
10
  static $theme = '';
11
  static $raw = '';
12
- static $num_posts = '';
13
  /**
14
  * Save default values to data base
15
  */
16
  static function install(){
17
  $defaults = self::getdefaults();
18
  foreach ($defaults as $option => $value) {
19
- $opt = get_option($option);
20
- if($opt === false)
21
- update_option($option, $value);
22
  if(!isset($type))
23
  $type = $opt==false?"activated":"reactivated";
24
  }
25
  self::whois($type);
26
- return;
27
  }
28
  /**
29
  * Delete all plugin options on uninstall
30
  */
31
  static function uninstall(){
32
  $defaults = self::getdefaults();
33
- if ( is_multisite() ) {
34
- $sites = wp_get_sites();
35
- foreach ($sites as $site) {
36
- switch_to_blog($site['blog_id']);
37
- foreach ($defaults as $option ) {
38
- delete_option($option);
39
- }
40
- }
41
- restore_current_blog();
42
- } else {
43
- foreach ($defaults as $option ) {
44
- delete_option($option);
45
- }
46
- }
47
  self::whois('uninstalled');
48
- return;
49
  }
50
  static function deactivate(){
51
  self::whois('deactivated');
@@ -53,31 +53,31 @@ class WP_Embed_FB {
53
  }
54
  /**
55
  * Default options
56
- */
57
  static function getdefaults(){
58
  return array(
59
- 'wpemfb_max_width' => '450',
60
- 'wpemfb_max_photos' => '25',
61
- 'wpemfb_max_posts' => '2',
62
- 'wpemfb_show_posts' => 'false',
63
- 'wpemfb_enqueue_style' => 'true',
64
- 'wpemfb_app_id' => '0',
65
- 'wpemfb_app_secret' => '0',
66
- 'wpemfb_proportions' => 0.36867,
67
- 'wpemfb_height' => '221.202',
68
- 'wpemfb_show_like' => 'true',
69
- 'wpemfb_fb_root' => 'true',
70
- 'wpemfb_theme' => 'default',
71
- 'wpemfb_show_follow' => 'true',
72
- 'wpemfb_raw_video' => 'false',
73
- 'wpemfb_raw_photo' => 'false',
74
- 'wpemfb_raw_post' => 'false',
75
- 'wpemfb_enq_lightbox' => 'true',
76
- 'wpemfb_enq_wpemfb' => 'true',
77
- 'wpemfb_enq_fbjs' => 'true',
78
- 'wpemfb_ev_local_tz' => 'true',
79
- 'wpemfb_raw_video_fb' => 'false',
80
- );
81
  }
82
  //("uninstalled","deactivated","activated","reactivated")
83
  protected static function whois($install){
@@ -99,225 +99,222 @@ class WP_Embed_FB {
99
  static function wp_enqueue_scripts(){
100
  if(get_option('wpemfb_enqueue_style') == 'true'){
101
  $theme = get_option('wpemfb_theme');
102
- wp_register_style( 'wpemfb-style', WPEMFBURL.'templates/'.$theme.'/wpemfb.css');
103
  wp_register_style( 'wpemfb-lightbox', WPEMFBURL.'lib/lightbox2/css/lightbox.css');
104
  wp_enqueue_style('wpemfb-style');
105
- wp_enqueue_style('wpemfb-lightbox');
106
  }
107
  if(get_option('wpemfb_enq_lightbox') == 'true'){
108
- wp_enqueue_script(
109
- 'wpemfb-lightbox',
110
- WPEMFBURL.'lib/lightbox2/js/lightbox.min.js',
111
- array( 'jquery' )
112
- );
113
  }
114
  if(get_option('wpemfb_enq_wpemfb') == 'true'){
115
  wp_enqueue_script(
116
  'wpemfb',
117
  WPEMFBURL.'lib/js/wpembedfb.js',
118
  array( 'jquery' )
119
- );
120
  }
121
  if(get_option('wpemfb_enq_fbjs') == 'true'){
122
  wp_enqueue_script(
123
  'wpemfbjs',
124
  WPEMFBURL.'lib/js/fb.js',
125
  array( 'jquery' )
126
- );
127
  $translation_array = array( 'local' => get_locale(), 'fb_id'=>get_option('wpemfb_app_id') );
128
- wp_localize_script( 'wpemfbjs', 'WEF', $translation_array );
129
- }
130
  }
131
  /**
132
  * Find facebook urls on a string and return content
133
  * @param string post content
134
- * @return string content with embeds if present.
135
  */
136
  static function the_content($the_content){
137
  preg_match_all("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", $the_content, $matches, PREG_SET_ORDER);
138
  if(!empty($matches) && is_array($matches)){
139
- foreach($matches as $match) {
140
- $the_content = preg_replace("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", self::fb_embed($match), $the_content, 1);
141
- }
142
  }
143
- return $the_content;
144
  }
145
  /**
146
  * Extract fb_id from the url
147
  * @param array $match[2]=url without ' https://www.facebook.com/ '
148
- * @return string Embedded content
149
  */
150
  static function fb_embed($match){
151
- self::$fbsdk = FaceInit::get_fbsdk();
152
- if(self::$fbsdk !== 'unactive') {
153
- //extract fbid from url good for profiles, pages, comunity pages, raw photos, events
154
- $vars = array();
155
- $type = '';
156
- parse_str(parse_url($match[2], PHP_URL_QUERY), $vars);
157
-
158
- $url = explode('?', $match[2]);
159
- $clean = explode('/', $url[0]);
160
- $end = end($clean);
161
- if (empty($end)) {
162
- array_pop($clean);
163
- }
164
- $last = end($clean);
165
- $fb_id = $last;
166
- //old embed ulr's
167
- if (isset($vars['fbid']))
168
- $fb_id = $vars['fbid'];
169
 
170
- //its an album
171
- if (array_search('media', $clean) !== false || isset($vars['set']) || $last == 'album.php') {
172
- $type = 'album';
173
- if ($last !== 'album.php') {
174
- $ids = explode('.', $vars['set']);
175
- $fb_id = $ids[1];
176
- }
177
- }
178
- /**
179
- * Filter the embed type.
180
- *
181
- * @since 1.8
182
- *
183
- * @param string $type the embed type.
184
- * @param array $clean url parts of the request.
185
- */
186
- $type = apply_filters('wpemfb_embed_type', $type, $clean);
187
- //its a post
188
- if (array_search('posts', $clean) !== false) {
189
- $fb_data = array('link' => $match[2], 'is_post' => '');
190
- return self::print_fb_data($fb_data);
191
- }
192
 
193
- if (!empty(self::$raw)) {
194
- $raw_photo = self::$raw;
195
- } else {
196
- $raw_photo = get_option('wpemfb_raw_photo') == 'true' ? 'true' : 'false';
197
- }
198
- //var_dump($raw_video);
199
- //die();
200
- //is video
201
- if (isset($vars['v'])) { //is video
202
- $fb_id = $vars['v'];
203
- }
204
- //photos
205
- if ('photo.php' == $last || (array_search('photos', $clean) !== false)) {
206
- if ($raw_photo == 'true') {
207
- return self::fb_api_get($fb_id, $match[2]);
208
- } else {
209
- $fb_data = array('link' => $match[2], 'is_post' => '');
210
- return self::print_fb_data($fb_data);
211
- }
212
- }
213
- return self::fb_api_get($fb_id, $match[2], $type);
214
- } else {
215
- $return = '';
216
- if(is_super_admin()){
217
- $return .= '<p>'.__('Add Facebook App ID and Secret on admin to make this plugin work.','wp-embed-facebook').'</p>';
218
- $return .= '<p><a href="'.admin_url("options-general.php?page=embedfacebook").'" target="_blank">'.__("WP Embed Facebook Settings","wp-embed-facebook").'</a></p>';
219
- $return .= '<p><a href="https://developers.facebook.com/apps" target="_blank">'.__("Your Facebook Apps","wp-embed-facebook").'</a></p>';
220
- }
221
- $return .= '<p><a href="https://www.facebook.com/'.$match[2].'" target="_blank" rel="nofollow">https://www.facebook.com/'.$match[2].'</a></p>';
222
- return $return;
223
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
  }
226
  /**
227
  * get data from fb using WP_Embed_FB::$fbsdk->api('/'.$fb_id) :)
228
- *
229
  * @param int facebook id
230
- * @param string facebook url
231
- * @type string type of embed
232
- * @return facebook api resulto or error
233
  */
234
  static function fb_api_get($fb_id, $url, $type=""){
235
  $wp_emb_fbsdk = self::$fbsdk;
236
- try {
237
- if($type == 'album')
238
- $api_string = $fb_id.'?fields=name,id,from,description,photos.fields(name,picture,source).limit('.get_option("wpemfb_max_photos").')';
239
- else
240
- $api_string = $fb_id;
241
 
242
- /**
243
- * Filter the fist fbsdk query
244
- *
245
- * @since 1.9
246
- *
247
- * @param string $api_string The fb api request string according to type
248
- * @param string $fb_id The id of the object being requested.
249
- * @param string $type The detected type of embed
250
- *
251
- */
252
- $fb_data = $wp_emb_fbsdk->api('/v2.3/'.apply_filters('wpemfb_api_string',$api_string,$fb_id,$type));
253
- $num_posts = self::$num_posts !== '' && is_numeric(self::$num_posts) ? self::$num_posts : get_option("wpemfb_max_posts");
254
- $api_string2 = '';
255
- if(isset($fb_data['embed_html']))
256
- $fb_data = array_merge($fb_data,array('is_video' => '1','link'=>$url));
257
- elseif( isset($fb_data['category']) && get_option("wpemfb_show_posts") == "true")
258
- $api_string2 = '/'.$fb_data['id'].'?fields=posts.limit('.$num_posts.'){message,shares,link,picture,object_id,likes.limit(1).summary(true),comments.limit(1).summary(true)}';
259
 
260
- /**
261
- * Filter the second fbsdk query if necessary
262
- *
263
- * @since 1.9
264
- *
265
- * @param string $api_string2 The second request string empty if not necessary
266
- * @param array $fb_data The result from the first query
267
- * @param string $type The detected type of embed
268
- *
269
- */
270
- $api_string2 = apply_filters('wpemfb_2nd_api_string',$api_string2,$fb_data,$type);
271
 
272
- if(!empty($api_string2)){
273
- $extra_data = $wp_emb_fbsdk->api('/v2.3/'.$api_string2);
274
- $fb_data = array_merge($fb_data,$extra_data);
275
- }
276
- /**
277
- * Filter all data received from facebook.
278
- *
279
- * @since 1.9
280
- *
281
- * @param array $fb_data the final result
282
- * @param string $type The detected type of embed
283
- */
284
- $fb_data = apply_filters('wpemfb_fb_data',$fb_data,$type);
285
 
286
- $res = self::print_fb_data($fb_data);
287
- } catch(FacebookApiException $e) {
288
- $res = '<p><a href="https://www.facebook.com/'.$url.'" target="_blank" rel="nofollow">https://www.facebook.com/'.$url.'</a>';
289
- if(is_super_admin()){
290
- $error = $e->getResult();
291
- $res .= '<br><span style="color: #4a0e13">'.__('Error').':&nbsp;'.$error['error']['message'].'</span>';
292
- }
293
- $res .= '</p>';
294
  }
295
- return $res;
 
 
296
  }
297
  /**
298
  * find out what kind of data we got from facebook
299
- *
300
  * @param array $fb_data result from facebook
301
- * @return string embedded content
302
  */
303
  static function print_fb_data($fb_data){
304
  if(isset($fb_data['is_video'])) { //is raw video
305
- if (!empty(self::$raw)) {
306
- $raw_video = self::$raw;
307
- } else {
308
- $raw_video = get_option('wpemfb_raw_video') == 'true' ? 'true' : 'false';
309
- }
310
- if ($raw_video == 'true') {
311
- $template = self::locate_template('video');
312
- } else {
313
- $template = self::locate_template('posts');
314
- }
315
  } elseif(isset($fb_data['is_post'])) { //is post
316
- $template = self::locate_template('posts');
317
  } elseif(isset($fb_data['start_time'])) { //is event
318
  $template = self::locate_template('event');
319
  } elseif(isset($fb_data['photos'])) { //is album
320
- $template = self::locate_template('album');
321
  } elseif(isset($fb_data['width'])) { //is raw photo
322
  $template = self::locate_template('photo');
323
  } elseif(isset($fb_data['category'])) { //is page
@@ -325,62 +322,62 @@ class WP_Embed_FB {
325
  $template = self::locate_template('com-page'); //is community page
326
  }else {
327
  $default = self::locate_template('page');
328
- /**
329
- * Add a new template for a specific facebook category
330
- *
331
- * for example a Museum create the new template at your-theme/plugins/wp-embed-facebook/museum.php
332
- * then on functions.php of your theme
333
- *
334
- * add_filter( 'wpemfb_category_template', 'your_function', 10, 2 );
335
- *
336
- * function your_function( $default, $category ) {
337
- * if($category == 'Museum/art gallery')
338
- * return WP_Embed_FB::locate_template('museum');
339
- * else
340
- * return $default;
341
- * }
342
- *
343
- * @since 1.0
344
- *
345
- * @param string $default file full path
346
- * @param array $fb_data['category'] data from facebook
347
- */
348
  $template = apply_filters('wpemfb_category_template', $default, $fb_data['category']);
349
  }
350
  } else { //is profile
351
  $template = self::locate_template('profile');
352
  }
353
- //get default variables to use on templates
354
- if(empty(self::$width)){
355
- $width = get_option('wpemfb_max_width');
356
- $height = get_option('wpemfb_height');
357
- } else {
358
- $width = self::$width;
359
- $height = self::$height;
360
- }
361
- $prop = get_option('wpemfb_proportions');
362
- ob_start();
363
- //show embed post on admin
364
- if(is_admin() && isset($fb_data['is_post'])) : ?>
365
- <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/es_LA/sdk.js#xfbml=1&version=v2.3"; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>
366
- <?php endif;
367
- /**
368
- * Change the file to include on a certain embed.
369
- *
370
- * @since 1.8
371
- *
372
- * @param string $template file full path
373
- * @param array $fb_data data from facebook
374
- */
375
- $template = apply_filters('wpemfb_template',$template,$fb_data);
376
  include( $template );
377
- return preg_replace('/^\s+|\n|\r|\s+$/m', '', ob_get_clean());
378
  }
379
  /**
380
  * Locate the template inside plugin or theme
381
- *
382
  * @param string $template_name Template file name
383
- * @return string Template location
384
  */
385
  static function locate_template($template_name){
386
  $theme = get_option('wpemfb_theme');
@@ -393,15 +390,15 @@ class WP_Embed_FB {
393
  }
394
  /*
395
  * Formatting functions.
396
- */
397
  /**
398
- * If a user has a lot of websites registered on fb this function will only link to the first one
399
  * @param string $urls separated by spaces
400
- * @return string first url
401
  */
402
  static function getwebsite($urls){
403
  $url = explode(' ',$urls);
404
- return $url[0];
405
  }
406
  /**
407
  * Shows a like button or a facebook like count of a page depending on settings
@@ -415,20 +412,15 @@ class WP_Embed_FB {
415
  if($opt === 'true') :
416
  ob_start();
417
  ?>
418
- <div class="fb-like"
419
- data-href="https://facebook.com/<?php echo $fb_id ?>"
420
- data-layout="button_count"
421
- data-action="like"
422
- data-show-faces="<?php echo $faces ? 'true' : 'false' ?>"
423
- data-share="<?php echo $share ? 'true' : 'false' ?>" >
424
- </div>
425
  <?php
426
  echo ob_get_clean();
427
  return;
428
  else :
429
  printf( __( '%d people like this.', 'wp-embed-facebook' ), $likes );
430
  return;
431
- endif;
432
  }
433
  /**
434
  * Shows a follow button depending on settings
@@ -439,30 +431,26 @@ class WP_Embed_FB {
439
  if($opt === 'true') :
440
  ob_start();
441
  ?>
442
- <div class="fb-follow"
443
- data-href="https://www.facebook.com/<?php echo $fb_id ?>"
444
- data-colorscheme="light"
445
- data-layout="button_count"
446
- data-show-faces="false">
447
- </div>
448
  <?php
449
  ob_end_flush();
450
- return;
451
- endif;
452
- }
453
  /**
454
  * Shortcode function
455
  * [facebook='url' width='600'] width is optional
456
  * @param array $atts [0]=>url ['width']=>embed width ['raw']=>for videos and photos
457
- * @return string
458
- */
459
  static function shortcode($atts){
460
  if(!empty($atts) && isset($atts[0])){
461
- $clean = trim($atts[0],'=');
462
- if( is_numeric($clean) )
463
- $url = '<p>https://www.facebook.com/'.$clean.'/</p>';
464
- else
465
- $url = '<p>'.$clean.'</p>';
466
 
467
  if(isset($atts['width'])){
468
  $prop = get_option('wpemfb_proportions');
@@ -472,9 +460,9 @@ class WP_Embed_FB {
472
  if(isset($atts['raw'])){
473
  self::$raw = $atts['raw'];
474
  }
475
- if(isset($atts['posts'])){
476
- self::$num_posts = $atts['posts'];
477
- }
478
  $embed = self::the_content($url);
479
  self::$height = self::$width = self::$raw = self::$num_posts = '';
480
  return $embed;
@@ -483,7 +471,7 @@ class WP_Embed_FB {
483
  }
484
  static function embed_register_handler($match){
485
  return self::fb_embed($match);
486
- }
487
  static function fb_root($ct){
488
  $root = '<div id="fb-root"></div>';
489
  $root .= "\n";
@@ -493,8 +481,8 @@ class WP_Embed_FB {
493
 
494
  /**
495
  * Triggering the FaceInit::init(); will give you access to the fb php sdk on FaceInit::$fbsdk which you can use to make any call shown here
496
- * https://developers.facebook.com/docs/reference/php/
497
- */
498
  class FaceInit {
499
  static $fbsdk = null;
500
  static function init(){
@@ -508,9 +496,9 @@ class FaceInit {
508
  else
509
  self::$fbsdk = 'unactive';
510
  }
511
- static function get_fbsdk(){
512
- if(self::$fbsdk == null)
513
- self::init();
514
- return self::$fbsdk;
515
- }
516
  }
9
  static $height = '';
10
  static $theme = '';
11
  static $raw = '';
12
+ static $num_posts = '';
13
  /**
14
  * Save default values to data base
15
  */
16
  static function install(){
17
  $defaults = self::getdefaults();
18
  foreach ($defaults as $option => $value) {
19
+ $opt = get_option($option);
20
+ if($opt === false)
21
+ update_option($option, $value);
22
  if(!isset($type))
23
  $type = $opt==false?"activated":"reactivated";
24
  }
25
  self::whois($type);
26
+ return;
27
  }
28
  /**
29
  * Delete all plugin options on uninstall
30
  */
31
  static function uninstall(){
32
  $defaults = self::getdefaults();
33
+ if ( is_multisite() ) {
34
+ $sites = wp_get_sites();
35
+ foreach ($sites as $site) {
36
+ switch_to_blog($site['blog_id']);
37
+ foreach ($defaults as $option ) {
38
+ delete_option($option);
39
+ }
40
+ }
41
+ restore_current_blog();
42
+ } else {
43
+ foreach ($defaults as $option ) {
44
+ delete_option($option);
45
+ }
46
+ }
47
  self::whois('uninstalled');
48
+ return;
49
  }
50
  static function deactivate(){
51
  self::whois('deactivated');
53
  }
54
  /**
55
  * Default options
56
+ */
57
  static function getdefaults(){
58
  return array(
59
+ 'wpemfb_max_width' => '450',
60
+ 'wpemfb_max_photos' => '25',
61
+ 'wpemfb_max_posts' => '2',
62
+ 'wpemfb_show_posts' => 'false',
63
+ 'wpemfb_enqueue_style' => 'true',
64
+ 'wpemfb_app_id' => '0',
65
+ 'wpemfb_app_secret' => '0',
66
+ 'wpemfb_proportions' => 0.36867,
67
+ 'wpemfb_height' => '221.202',
68
+ 'wpemfb_show_like' => 'true',
69
+ 'wpemfb_fb_root' => 'true',
70
+ 'wpemfb_theme' => 'default',
71
+ 'wpemfb_show_follow' => 'true',
72
+ 'wpemfb_raw_video' => 'false',
73
+ 'wpemfb_raw_photo' => 'false',
74
+ 'wpemfb_raw_post' => 'false',
75
+ 'wpemfb_enq_lightbox' => 'true',
76
+ 'wpemfb_enq_wpemfb' => 'true',
77
+ 'wpemfb_enq_fbjs' => 'true',
78
+ 'wpemfb_ev_local_tz' => 'true',
79
+ 'wpemfb_raw_video_fb' => 'false',
80
+ );
81
  }
82
  //("uninstalled","deactivated","activated","reactivated")
83
  protected static function whois($install){
99
  static function wp_enqueue_scripts(){
100
  if(get_option('wpemfb_enqueue_style') == 'true'){
101
  $theme = get_option('wpemfb_theme');
102
+ wp_register_style( 'wpemfb-style', WPEMFBURL.'templates/'.$theme.'/wpemfb.css');
103
  wp_register_style( 'wpemfb-lightbox', WPEMFBURL.'lib/lightbox2/css/lightbox.css');
104
  wp_enqueue_style('wpemfb-style');
105
+ wp_enqueue_style('wpemfb-lightbox');
106
  }
107
  if(get_option('wpemfb_enq_lightbox') == 'true'){
108
+ wp_enqueue_script(
109
+ 'wpemfb-lightbox',
110
+ WPEMFBURL.'lib/lightbox2/js/lightbox.min.js',
111
+ array( 'jquery' )
112
+ );
113
  }
114
  if(get_option('wpemfb_enq_wpemfb') == 'true'){
115
  wp_enqueue_script(
116
  'wpemfb',
117
  WPEMFBURL.'lib/js/wpembedfb.js',
118
  array( 'jquery' )
119
+ );
120
  }
121
  if(get_option('wpemfb_enq_fbjs') == 'true'){
122
  wp_enqueue_script(
123
  'wpemfbjs',
124
  WPEMFBURL.'lib/js/fb.js',
125
  array( 'jquery' )
126
+ );
127
  $translation_array = array( 'local' => get_locale(), 'fb_id'=>get_option('wpemfb_app_id') );
128
+ wp_localize_script( 'wpemfbjs', 'WEF', $translation_array );
129
+ }
130
  }
131
  /**
132
  * Find facebook urls on a string and return content
133
  * @param string post content
134
+ * @return string content with embeds if present.
135
  */
136
  static function the_content($the_content){
137
  preg_match_all("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", $the_content, $matches, PREG_SET_ORDER);
138
  if(!empty($matches) && is_array($matches)){
139
+ foreach($matches as $match) {
140
+ $the_content = preg_replace("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", self::fb_embed($match), $the_content, 1);
141
+ }
142
  }
143
+ return $the_content;
144
  }
145
  /**
146
  * Extract fb_id from the url
147
  * @param array $match[2]=url without ' https://www.facebook.com/ '
148
+ * @return string Embedded content
149
  */
150
  static function fb_embed($match){
151
+ self::$fbsdk = FaceInit::get_fbsdk();
152
+ if(self::$fbsdk !== 'unactive') {
153
+ //extract fbid from url good for profiles, pages, comunity pages, raw photos, events
154
+ $vars = array();
155
+ $type = '';
156
+ parse_str(parse_url($match[2], PHP_URL_QUERY), $vars);
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ $url = explode('?', $match[2]);
159
+ $clean = explode('/', $url[0]);
160
+ $end = end($clean);
161
+ if (empty($end)) {
162
+ array_pop($clean);
163
+ }
164
+ $last = end($clean);
165
+ $fb_id = $last;
166
+ //old embed ulr's
167
+ if (isset($vars['fbid']))
168
+ $fb_id = $vars['fbid'];
 
 
 
 
 
 
 
 
 
 
 
169
 
170
+ //its an album
171
+ if (array_search('media', $clean) !== false || isset($vars['set']) || $last == 'album.php') {
172
+ $type = 'album';
173
+ if ($last !== 'album.php') {
174
+ $ids = explode('.', $vars['set']);
175
+ $fb_id = $ids[1];
176
+ }
177
+ }
178
+ /**
179
+ * Filter the embed type.
180
+ *
181
+ * @since 1.8
182
+ *
183
+ * @param string $type the embed type.
184
+ * @param array $clean url parts of the request.
185
+ */
186
+ $type = apply_filters('wpemfb_embed_type', $type, $clean);
187
+ //its a post
188
+ if (array_search('posts', $clean) !== false) {
189
+ $fb_data = array('link' => $match[2], 'is_post' => '');
190
+ return self::print_fb_data($fb_data);
191
+ }
192
+ if (isset($vars['v'])) { //is video
193
+ $fb_id = $vars['v'];
194
+ return self::fb_api_get($fb_id, $match[2], 'video');
195
+ }
196
+ if (!empty(self::$raw)) {
197
+ $raw_photo = self::$raw;
198
+ } else {
199
+ $raw_photo = get_option('wpemfb_raw_photo') == 'true' ? 'true' : 'false';
200
+ }
201
+ //photos
202
+ if ('photo.php' == $last || (array_search('photos', $clean) !== false)) {
203
+ if ($raw_photo == 'true') {
204
+ return self::fb_api_get($fb_id, $match[2]);
205
+ } else {
206
+ $fb_data = array('link' => $match[2], 'is_post' => '');
207
+ return self::print_fb_data($fb_data);
208
+ }
209
+ }
210
+ return self::fb_api_get($fb_id, $match[2], $type);
211
+ } else {
212
+ $return = '';
213
+ if(is_super_admin()){
214
+ $return .= '<p>'.__('Add Facebook App ID and Secret on admin to make this plugin work.','wp-embed-facebook').'</p>';
215
+ $return .= '<p><a href="'.admin_url("options-general.php?page=embedfacebook").'" target="_blank">'.__("WP Embed Facebook Settings","wp-embed-facebook").'</a></p>';
216
+ $return .= '<p><a href="https://developers.facebook.com/apps" target="_blank">'.__("Your Facebook Apps","wp-embed-facebook").'</a></p>';
217
+ }
218
+ $return .= '<p><a href="https://www.facebook.com/'.$match[2].'" target="_blank" rel="nofollow">https://www.facebook.com/'.$match[2].'</a></p>';
219
+ return $return;
220
+ }
221
 
222
  }
223
  /**
224
  * get data from fb using WP_Embed_FB::$fbsdk->api('/'.$fb_id) :)
225
+ *
226
  * @param int facebook id
227
+ * @param string facebook url
228
+ * @type string type of embed
229
+ * @return facebook api resulto or error
230
  */
231
  static function fb_api_get($fb_id, $url, $type=""){
232
  $wp_emb_fbsdk = self::$fbsdk;
233
+ try {
234
+ if($type == 'album')
235
+ $api_string = $fb_id.'?fields=name,id,from,description,photos.fields(name,picture,source).limit('.get_option("wpemfb_max_photos").')';
236
+ else
237
+ $api_string = $fb_id;
238
 
239
+ /**
240
+ * Filter the fist fbsdk query
241
+ *
242
+ * @since 1.9
243
+ *
244
+ * @param string $api_string The fb api request string according to type
245
+ * @param string $fb_id The id of the object being requested.
246
+ * @param string $type The detected type of embed
247
+ *
248
+ */
249
+ $fb_data = $wp_emb_fbsdk->api('/v2.3/'.apply_filters('wpemfb_api_string',$api_string,$fb_id,$type));
250
+ $num_posts = self::$num_posts !== '' && is_numeric(self::$num_posts) ? self::$num_posts : get_option("wpemfb_max_posts");
251
+ $api_string2 = '';
252
+ if(isset($fb_data['embed_html']))
253
+ $fb_data = array_merge($fb_data,array('is_video' => '1','link'=>$url));
254
+ elseif( isset($fb_data['category']) && get_option("wpemfb_show_posts") == "true")
255
+ $api_string2 = '/'.$fb_data['id'].'?fields=posts.limit('.$num_posts.'){message,shares,link,picture,object_id,likes.limit(1).summary(true),comments.limit(1).summary(true)}';
256
 
257
+ /**
258
+ * Filter the second fbsdk query if necessary
259
+ *
260
+ * @since 1.9
261
+ *
262
+ * @param string $api_string2 The second request string empty if not necessary
263
+ * @param array $fb_data The result from the first query
264
+ * @param string $type The detected type of embed
265
+ *
266
+ */
267
+ $api_string2 = apply_filters('wpemfb_2nd_api_string',$api_string2,$fb_data,$type);
268
 
269
+ if(!empty($api_string2)){
270
+ $extra_data = $wp_emb_fbsdk->api('/v2.3/'.$api_string2);
271
+ $fb_data = array_merge($fb_data,$extra_data);
272
+ }
273
+ /**
274
+ * Filter all data received from facebook.
275
+ *
276
+ * @since 1.9
277
+ *
278
+ * @param array $fb_data the final result
279
+ * @param string $type The detected type of embed
280
+ */
281
+ $fb_data = apply_filters('wpemfb_fb_data',$fb_data,$type);
282
 
283
+ $res = self::print_fb_data($fb_data);
284
+ } catch(FacebookApiException $e) {
285
+ $res = '<p><a href="https://www.facebook.com/'.$url.'" target="_blank" rel="nofollow">https://www.facebook.com/'.$url.'</a>';
286
+ if(is_super_admin()){
287
+ $error = $e->getResult();
288
+ $res .= '<br><span style="color: #4a0e13">'.__('Error').':&nbsp;'.$error['error']['message'].'</span>';
 
 
289
  }
290
+ $res .= '</p>';
291
+ }
292
+ return $res;
293
  }
294
  /**
295
  * find out what kind of data we got from facebook
296
+ *
297
  * @param array $fb_data result from facebook
298
+ * @return string embedded content
299
  */
300
  static function print_fb_data($fb_data){
301
  if(isset($fb_data['is_video'])) { //is raw video
302
+ if (!empty(self::$raw)) {
303
+ $raw_video = self::$raw;
304
+ } else {
305
+ $raw_video = get_option('wpemfb_raw_video') == 'true' ? 'true' : 'false';
306
+ }
307
+ if ($raw_video == 'true') {
308
+ $template = self::locate_template('video');
309
+ } else {
310
+ $template = self::locate_template('posts');
311
+ }
312
  } elseif(isset($fb_data['is_post'])) { //is post
313
+ $template = self::locate_template('posts');
314
  } elseif(isset($fb_data['start_time'])) { //is event
315
  $template = self::locate_template('event');
316
  } elseif(isset($fb_data['photos'])) { //is album
317
+ $template = self::locate_template('album');
318
  } elseif(isset($fb_data['width'])) { //is raw photo
319
  $template = self::locate_template('photo');
320
  } elseif(isset($fb_data['category'])) { //is page
322
  $template = self::locate_template('com-page'); //is community page
323
  }else {
324
  $default = self::locate_template('page');
325
+ /**
326
+ * Add a new template for a specific facebook category
327
+ *
328
+ * for example a Museum create the new template at your-theme/plugins/wp-embed-facebook/museum.php
329
+ * then on functions.php of your theme
330
+ *
331
+ * add_filter( 'wpemfb_category_template', 'your_function', 10, 2 );
332
+ *
333
+ * function your_function( $default, $category ) {
334
+ * if($category == 'Museum/art gallery')
335
+ * return WP_Embed_FB::locate_template('museum');
336
+ * else
337
+ * return $default;
338
+ * }
339
+ *
340
+ * @since 1.0
341
+ *
342
+ * @param string $default file full path
343
+ * @param array $fb_data['category'] data from facebook
344
+ */
345
  $template = apply_filters('wpemfb_category_template', $default, $fb_data['category']);
346
  }
347
  } else { //is profile
348
  $template = self::locate_template('profile');
349
  }
350
+ //get default variables to use on templates
351
+ if(empty(self::$width)){
352
+ $width = get_option('wpemfb_max_width');
353
+ $height = get_option('wpemfb_height');
354
+ } else {
355
+ $width = self::$width;
356
+ $height = self::$height;
357
+ }
358
+ $prop = get_option('wpemfb_proportions');
359
+ ob_start();
360
+ //show embed post on admin
361
+ if(is_admin() && isset($fb_data['is_post'])) : ?>
362
+ <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/es_LA/sdk.js#xfbml=1&version=v2.3"; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>
363
+ <?php endif;
364
+ /**
365
+ * Change the file to include on a certain embed.
366
+ *
367
+ * @since 1.8
368
+ *
369
+ * @param string $template file full path
370
+ * @param array $fb_data data from facebook
371
+ */
372
+ $template = apply_filters('wpemfb_template',$template,$fb_data);
373
  include( $template );
374
+ return preg_replace('/^\s+|\n|\r|\s+$/m', '', ob_get_clean());
375
  }
376
  /**
377
  * Locate the template inside plugin or theme
378
+ *
379
  * @param string $template_name Template file name
380
+ * @return string Template location
381
  */
382
  static function locate_template($template_name){
383
  $theme = get_option('wpemfb_theme');
390
  }
391
  /*
392
  * Formatting functions.
393
+ */
394
  /**
395
+ * If a user has a lot of websites registered on fb this function will only link to the first one
396
  * @param string $urls separated by spaces
397
+ * @return string first url
398
  */
399
  static function getwebsite($urls){
400
  $url = explode(' ',$urls);
401
+ return $url[0];
402
  }
403
  /**
404
  * Shows a like button or a facebook like count of a page depending on settings
412
  if($opt === 'true') :
413
  ob_start();
414
  ?>
415
+ <div class="fb-like" data-href="https://facebook.com/<?php echo $fb_id ?>" data-layout="button_count" data-action="like" data-show-faces="<?php echo $faces ? 'true' : 'false' ?>" data-share="<?php echo $share ? 'true' : 'false' ?>" >
416
+ </div>
 
 
 
 
 
417
  <?php
418
  echo ob_get_clean();
419
  return;
420
  else :
421
  printf( __( '%d people like this.', 'wp-embed-facebook' ), $likes );
422
  return;
423
+ endif;
424
  }
425
  /**
426
  * Shows a follow button depending on settings
431
  if($opt === 'true') :
432
  ob_start();
433
  ?>
434
+ <div class="fb-follow" data-href="https://www.facebook.com/<?php echo $fb_id ?>" data-colorscheme="light" data-layout="button_count" data-show-faces="false">
435
+ </div>
 
 
 
 
436
  <?php
437
  ob_end_flush();
438
+ return;
439
+ endif;
440
+ }
441
  /**
442
  * Shortcode function
443
  * [facebook='url' width='600'] width is optional
444
  * @param array $atts [0]=>url ['width']=>embed width ['raw']=>for videos and photos
445
+ * @return string
446
+ */
447
  static function shortcode($atts){
448
  if(!empty($atts) && isset($atts[0])){
449
+ $clean = trim($atts[0],'=');
450
+ if( is_numeric($clean) )
451
+ $url = '<p>https://www.facebook.com/'.$clean.'/</p>';
452
+ else
453
+ $url = '<p>'.$clean.'</p>';
454
 
455
  if(isset($atts['width'])){
456
  $prop = get_option('wpemfb_proportions');
460
  if(isset($atts['raw'])){
461
  self::$raw = $atts['raw'];
462
  }
463
+ if(isset($atts['posts'])){
464
+ self::$num_posts = $atts['posts'];
465
+ }
466
  $embed = self::the_content($url);
467
  self::$height = self::$width = self::$raw = self::$num_posts = '';
468
  return $embed;
471
  }
472
  static function embed_register_handler($match){
473
  return self::fb_embed($match);
474
+ }
475
  static function fb_root($ct){
476
  $root = '<div id="fb-root"></div>';
477
  $root .= "\n";
481
 
482
  /**
483
  * Triggering the FaceInit::init(); will give you access to the fb php sdk on FaceInit::$fbsdk which you can use to make any call shown here
484
+ * https://developers.facebook.com/docs/reference/php/
485
+ */
486
  class FaceInit {
487
  static $fbsdk = null;
488
  static function init(){
496
  else
497
  self::$fbsdk = 'unactive';
498
  }
499
+ static function get_fbsdk(){
500
+ if(self::$fbsdk == null)
501
+ self::init();
502
+ return self::$fbsdk;
503
+ }
504
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: Facebook, facebook, Social Plugins, embed facebook, facebook video, facebook posts, facebook publication, facebook publications, facebook event, facebook events, facebook pages, facebook page, facebook profiles, facebook album, facebook albums, facebook photos, facebook photo, social,
5
  Requires at least: 3.8.1
6
  Tested up to: 4.3
7
- Stable tag: 1.9.6.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -82,6 +82,10 @@ The embedded post code comes directly from facebook so there is no easy way to c
82
 
83
  == Changelog ==
84
 
 
 
 
 
85
  = 1.9.6.5 =
86
  * Fixed more things on multisite
87
  * Fixed Page Template HTML
@@ -219,5 +223,5 @@ The embedded post code comes directly from facebook so there is no easy way to c
219
 
220
  == Upgrade Notice ==
221
 
222
- = 1.9.6.5 =
223
- * Fixed more thing related to multisite and page template errors.
4
  Tags: Facebook, facebook, Social Plugins, embed facebook, facebook video, facebook posts, facebook publication, facebook publications, facebook event, facebook events, facebook pages, facebook page, facebook profiles, facebook album, facebook albums, facebook photos, facebook photo, social,
5
  Requires at least: 3.8.1
6
  Tested up to: 4.3
7
+ Stable tag: 1.9.6.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
82
 
83
  == Changelog ==
84
 
85
+ = 1.9.6.6 =
86
+ * Fixed Embed Video Error
87
+ * Fixed like and follow button html
88
+
89
  = 1.9.6.5 =
90
  * Fixed more things on multisite
91
  * Fixed Page Template HTML
223
 
224
  == Upgrade Notice ==
225
 
226
+ = 1.9.6.6 =
227
+ * Fixed video embed error & like button html
wp-embed-facebook.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP Embed Facebook
4
  Plugin URI: http://www.wpembedfb.com
5
  Description: Embed a Facebook video, photo, album, event, page, profile, or post. Copy any facebook url to a single line on your post, or use shortcode [facebook='url' width='' ] more info at <a href="http://www.wpembedfb.com" title="plugin website">www.wpembedfb.com</a>
6
  Author: Miguel Sirvent
7
- Version: 1.9.6.5
8
  Author URI: http://profiles.wordpress.org/poxtron/
9
  */
10
 
4
  Plugin URI: http://www.wpembedfb.com
5
  Description: Embed a Facebook video, photo, album, event, page, profile, or post. Copy any facebook url to a single line on your post, or use shortcode [facebook='url' width='' ] more info at <a href="http://www.wpembedfb.com" title="plugin website">www.wpembedfb.com</a>
6
  Author: Miguel Sirvent
7
+ Version: 1.9.6.6
8
  Author URI: http://profiles.wordpress.org/poxtron/
9
  */
10