WP Embed Facebook - Version 1.2.1

Version Description

  • Updated Instructions
  • Change theme template directory
Download this release

Release Info

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

Code changes from version 1.3 to 1.2.1

lib/admin.php CHANGED
@@ -4,84 +4,68 @@ class EmbFbAdmin{
4
  add_options_page('EmbedFacebook', 'Embed Facebook', 'manage_options', 'embedfacebook', array('EmbFbAdmin', 'embedfb_page'));
5
  }
6
  static function savedata(){
7
- if(isset($_POST['wpemfb_app_secret'], $_POST['wpemfb_app_id' ] )) {
8
- if($_POST['wpemfb_app_id'] && $_POST['wpemfb_app_secret']){
 
 
 
 
9
  if ( !is_multisite() ) {
10
- update_option('wpemfb_app_id',$_POST['wpemfb_app_id']);
11
- update_option('wpemfb_app_secret',$_POST['wpemfb_app_secret']);
12
  }
13
- else {
14
- update_site_option('wpemfb_app_id',$_POST['wpemfb_app_id']);
15
- update_site_option('wpemfb_app_secret',$_POST['wpemfb_app_secret']);
16
  }
17
  }
18
- if(isset($_POST['wpemfb_max_width'])){
19
- $prop = get_option('wpemfb_proportions') * $_POST['wpemfb_max_width'];
20
  if ( !is_multisite() ) {
21
- update_option('wpemfb_max_width', $_POST['wpemfb_max_width']);
22
  update_option('wpemfb_height', $prop );
23
  }
24
- else {
25
- update_site_option('wpemfb_max_width', $_POST['wpemfb_max_width']);
26
  update_site_option('wpemfb_height', $prop);
27
  }
28
  }
29
- if(isset($_POST['wpemfb_theme'])){
30
- if ( !is_multisite() )
31
- update_option('wpemfb_theme', $_POST['wpemfb_theme']);
32
- else
33
- update_site_option('wpemfb_theme', $_POST['wpemfb_theme']);
34
- }
35
  if(isset($_POST['wpemfb_show_like'])){
36
  if ( !is_multisite() )
37
  update_option('wpemfb_show_like', 'true');
38
- else
39
  update_site_option('wpemfb_show_like', 'true');
40
  }else{
41
  if ( !is_multisite() ) {
42
  update_option('wpemfb_show_like', 'false');
43
  }
44
- else {
45
  update_site_option('wpemfb_show_like', 'false');
46
  }
47
  }
48
  if(isset($_POST['wpemfb_enqueue_style'])){
49
  if ( !is_multisite() )
50
  update_option('wpemfb_enqueue_style', 'true');
51
- else
52
  update_site_option('wpemfb_enqueue_style', 'true');
53
  }else{
54
  if ( !is_multisite() ) {
55
  update_option('wpemfb_enqueue_style', 'false');
56
  }
57
- else {
58
- update_site_option('wpemfb_enqueue_style', 'false');
59
- }
60
- }
61
- if(isset($_POST['wpemfb_fb_root'])){
62
- if ( !is_multisite() )
63
- update_option('wpemfb_fb_root', 'true');
64
- else // TODO: multiple fb apps for each site
65
- update_site_option('wpemfb_fb_root', 'true');
66
- }else{
67
- if ( !is_multisite() ) {
68
- update_option('wpemfb_fb_root', 'false');
69
- }
70
  else { // TODO: multiple fb apps for each site
71
- update_site_option('wpemfb_fb_root', 'false');
72
  }
73
  }
74
  }
 
75
  }
76
  static function embedfb_page() {
77
- if(isset($_POST['submit']) && check_admin_referer( 'wp-embed-fb','save-data' )){
 
78
  self::savedata();
79
  }
80
  $checked = (get_option('wpemfb_enqueue_style') === 'true') ? 'checked' : '' ;
81
  $checked2 = (get_option('wpemfb_show_like') === 'true') ? 'checked' : '' ;
82
- $checked3 = (get_option('wpemfb_fb_root') === 'true') ? 'checked' : '' ;
83
- $sel1 = (get_option('wpemfb_theme') === 'default') ? 'selected' : '' ;
84
- $sel2 = (get_option('wpemfb_theme') === 'classic') ? 'selected' : '' ;
85
  ?>
86
  <div class="wrap">
87
  <h2>WP Embed Facebook</h2>
@@ -91,7 +75,6 @@ class EmbFbAdmin{
91
  <div class="welcome-panel-column">
92
  <form id="config-form" action="#" method="post">
93
  <table class="form-table">
94
- <?php wp_nonce_field( 'wp-embed-fb','save-data' ); ?>
95
  <tbody>
96
  <tr>
97
  <h3><?php _e('Facebook application data', 'wp-embed-fb') ?></h3>
@@ -99,73 +82,59 @@ class EmbFbAdmin{
99
  <tr valign="middle">
100
  <th>App ID</th>
101
  <td>
102
- <input type="text" name="wpemfb_app_id" required value="<?php echo get_option('wpemfb_app_id') ?>" />
103
  </td>
104
  </tr>
105
  <tr valign="middle">
106
  <th>App Secret</th>
107
  <td>
108
- <input type="text" name="wpemfb_app_secret" required value="<?php echo get_option('wpemfb_app_secret') ?>" />
109
  </td>
110
  </tr>
111
- <tr>
112
- <th><?php _e("Theme to use", 'wp-embed-fb') ?></th>
113
- <td>
114
- <select name="wpemfb_theme">
115
- <option value="default" <?php echo $sel1 ?> >Default</option>
116
- <option value="classic" <?php echo $sel2 ?> >Classic</option>
117
- </select>
118
- </td>
119
- </tr>
120
  <tr>
121
  <th>
 
122
  <h4><?php _e("Other Options", 'wp-embed-fb') ?></h4>
 
 
123
  </th>
124
  </tr>
125
  <tr valign="middle">
126
  <th><?php _e('Fb Cover Embed Width','wp-embed-fb') ?></th>
127
  <td>
128
- <input type="text" name="wpemfb_max_width" value="<?php echo get_option('wpemfb_max_width') ?>" />
129
  </td>
130
  </tr>
131
- <tr valign="middle">
132
- <th><?php _e('Add like button to pages','wp-embed-fb') ?></th>
133
- <td>
134
- <input type="checkbox" name="wpemfb_show_like" <?php echo $checked2 ?> />
135
- </td>
136
- </tr>
137
  <tr valign="middle">
138
  <th><?php _e('Enqueue Styles','wp-embed-fb') ?></th>
139
  <td>
140
- <input type="checkbox" name="wpemfb_enqueue_style" <?php echo $checked ?> />
141
  </td>
142
  </tr>
143
  <tr valign="middle">
144
- <th><?php _e('Add fb-root and javascript on top of content','wp-embed-fb') ?><br><small><?php _e('Some themes may not need this','wp-embed-fb') ?></small></th>
145
  <td>
146
- <input type="checkbox" name="wpemfb_fb_root" <?php echo $checked3 ?> />
147
  </td>
148
- </tr>
149
  <tr>
150
  <td>
151
  <?php //echo wp_nonce_field('wpebfb','nonce'); ?>
152
- <input type="submit" name="submit" class="button button-primary button-hero" value="<?php _e('Save','wp-embed-fb') ?>" />
153
  </td>
154
  </tr>
155
  </tbody>
156
  </table>
157
  </form
158
  <ul class="">
159
- <!--
160
  <li>
161
  <a href="http://www.saliuitl.org/wp-embed-fb/customize"><?php _e('Customize','wp-embed-fb') ?></a>
162
  </li>
163
  <li>
164
  <a href="http://www.saliuitl.org/wp-embed-fb/support"><?php _e('Support','wp-embed-fb') ?></a>
165
- </li>
166
- -->
167
  <li>
168
- <a href="http://www.saliuitl.org/en/wp-embed-facebook"><?php _e('Plugin Web Site','wp-embed-fb') ?></a>
169
  </li>
170
  </ul>
171
  </div>
@@ -175,7 +144,10 @@ class EmbFbAdmin{
175
  <div class="welcome-panel-column welcome-panel-last">
176
  <h3 style="color:red;"><?php _e('Donate!', 'wp-embed-fb') ?></h3>
177
  <p><?php _e('Help me keep this plugin up to date', 'wp-embed-fb') ?></p>
178
- <p><strong><?php _e('Click the taco !', 'wp-embed-fb') ?></strong></p>
 
 
 
179
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
180
  <input type="hidden" name="cmd" value="_s-xclick">
181
  <input type="hidden" name="hosted_button_id" value="9TEJ8CGXMJEDG">
4
  add_options_page('EmbedFacebook', 'Embed Facebook', 'manage_options', 'embedfacebook', array('EmbFbAdmin', 'embedfb_page'));
5
  }
6
  static function savedata(){
7
+ //if ( !empty($_POST) && check_admin_referer('wp-embed-fb','nonce') )
8
+ if(isset($_POST['appsecret'], $_POST['appid' ] )) {
9
+ $wpemfb_width = get_option('wpemfb_max_width');
10
+ $proportions = get_option('wpemfb_proportions');
11
+
12
+ if($_POST['appid'] && $_POST['appsecret']){
13
  if ( !is_multisite() ) {
14
+ update_option('wpemfb_app_id',$_POST['appid']);
15
+ update_option('wpemfb_app_secret',$_POST['appsecret']);
16
  }
17
+ else { // TODO: multiple fb apps for each site
18
+ update_site_option('wpemfb_app_id',$_POST['appid']);
19
+ update_site_option('wpemfb_app_secret',$_POST['appsecret']);
20
  }
21
  }
22
+ if(isset($_POST['max-width'])){
23
+ $prop = get_option('wpemfb_proportions') * $_POST['max-width'];
24
  if ( !is_multisite() ) {
25
+ update_option('wpemfb_max_width', $_POST['max-width']);
26
  update_option('wpemfb_height', $prop );
27
  }
28
+ else { // TODO: multiple fb apps for each site
29
+ update_site_option('wpemfb_max_width', $_POST['max-width']);
30
  update_site_option('wpemfb_height', $prop);
31
  }
32
  }
 
 
 
 
 
 
33
  if(isset($_POST['wpemfb_show_like'])){
34
  if ( !is_multisite() )
35
  update_option('wpemfb_show_like', 'true');
36
+ else // TODO: multiple fb apps for each site
37
  update_site_option('wpemfb_show_like', 'true');
38
  }else{
39
  if ( !is_multisite() ) {
40
  update_option('wpemfb_show_like', 'false');
41
  }
42
+ else { // TODO: multiple fb apps for each site
43
  update_site_option('wpemfb_show_like', 'false');
44
  }
45
  }
46
  if(isset($_POST['wpemfb_enqueue_style'])){
47
  if ( !is_multisite() )
48
  update_option('wpemfb_enqueue_style', 'true');
49
+ else // TODO: multiple fb apps for each site
50
  update_site_option('wpemfb_enqueue_style', 'true');
51
  }else{
52
  if ( !is_multisite() ) {
53
  update_option('wpemfb_enqueue_style', 'false');
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  else { // TODO: multiple fb apps for each site
56
+ update_site_option('wpemfb_enqueue_style', 'false');
57
  }
58
  }
59
  }
60
+
61
  }
62
  static function embedfb_page() {
63
+ //global $new_emb_fbsdk; //TODO: eliminate this test
64
+ if(isset($_POST['submit'])){
65
  self::savedata();
66
  }
67
  $checked = (get_option('wpemfb_enqueue_style') === 'true') ? 'checked' : '' ;
68
  $checked2 = (get_option('wpemfb_show_like') === 'true') ? 'checked' : '' ;
 
 
 
69
  ?>
70
  <div class="wrap">
71
  <h2>WP Embed Facebook</h2>
75
  <div class="welcome-panel-column">
76
  <form id="config-form" action="#" method="post">
77
  <table class="form-table">
 
78
  <tbody>
79
  <tr>
80
  <h3><?php _e('Facebook application data', 'wp-embed-fb') ?></h3>
82
  <tr valign="middle">
83
  <th>App ID</th>
84
  <td>
85
+ <input type="text" name="appid" id="appid" class="input" required="" value="<?php echo get_option('wpemfb_app_id') ?>" />
86
  </td>
87
  </tr>
88
  <tr valign="middle">
89
  <th>App Secret</th>
90
  <td>
91
+ <input type="text" name="appsecret" id="appsecret" class="input" required="" value="<?php echo get_option('wpemfb_app_secret') ?>" />
92
  </td>
93
  </tr>
 
 
 
 
 
 
 
 
 
94
  <tr>
95
  <th>
96
+ <td>
97
  <h4><?php _e("Other Options", 'wp-embed-fb') ?></h4>
98
+ </td>
99
+
100
  </th>
101
  </tr>
102
  <tr valign="middle">
103
  <th><?php _e('Fb Cover Embed Width','wp-embed-fb') ?></th>
104
  <td>
105
+ <input type="text" name="max-width" id="max-width" class="input" value="<?php echo get_option('wpemfb_max_width') ?>" /
106
  </td>
107
  </tr>
 
 
 
 
 
 
108
  <tr valign="middle">
109
  <th><?php _e('Enqueue Styles','wp-embed-fb') ?></th>
110
  <td>
111
+ <input type="checkbox" name="wpemfb_enqueue_style" <?php echo $checked ?> /><br>
112
  </td>
113
  </tr>
114
  <tr valign="middle">
115
+ <th><?php _e('Add like button to pages','wp-embed-fb') ?></th>
116
  <td>
117
+ <input type="checkbox" name="wpemfb_show_like" <?php echo $checked2 ?> /><br>
118
  </td>
119
+ </tr>
120
  <tr>
121
  <td>
122
  <?php //echo wp_nonce_field('wpebfb','nonce'); ?>
123
+ <input type="submit" name="submit" id="save-config" class="button button-primary button-hero" value="<?php _e('Save','wp-embed-fb') ?>" />
124
  </td>
125
  </tr>
126
  </tbody>
127
  </table>
128
  </form
129
  <ul class="">
 
130
  <li>
131
  <a href="http://www.saliuitl.org/wp-embed-fb/customize"><?php _e('Customize','wp-embed-fb') ?></a>
132
  </li>
133
  <li>
134
  <a href="http://www.saliuitl.org/wp-embed-fb/support"><?php _e('Support','wp-embed-fb') ?></a>
135
+ </li>
 
136
  <li>
137
+ <a href="http://www.saliuitl.org/wp-embed-fb"><?php _e('Plugin Web Site','wp-embed-fb') ?></a>
138
  </li>
139
  </ul>
140
  </div>
144
  <div class="welcome-panel-column welcome-panel-last">
145
  <h3 style="color:red;"><?php _e('Donate!', 'wp-embed-fb') ?></h3>
146
  <p><?php _e('Help me keep this plugin up to date', 'wp-embed-fb') ?></p>
147
+ <p>
148
+ <strong><?php _e('Click the taco !', 'wp-embed-fb') ?></strong><br>
149
+ <small><?php _e('3 USD Minimun Suggested Donation', 'wp-embed-fb') ?></small>
150
+ </p>
151
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
152
  <input type="hidden" name="cmd" value="_s-xclick">
153
  <input type="hidden" name="hosted_button_id" value="9TEJ8CGXMJEDG">
lib/core.php CHANGED
@@ -1,15 +1,7 @@
1
  <?php
2
- /*
3
- * Main Class of the plugin.
4
- */
5
  class WP_Embed_FB {
6
  static $fbsdk;
7
- static $width = '';
8
- static $height = '';
9
- static $theme = '';
10
- /*
11
- * Save default values to data base
12
- */
13
  static function install(){
14
  $defaults = self::getdefaults();
15
  foreach ($defaults as $option => $value) {
@@ -18,7 +10,7 @@ class WP_Embed_FB {
18
  if($opt === false)
19
  update_option($option, $value);
20
  }
21
- else { // TODO: multiple fb apps for each site probably not needed for public data
22
  $opt = get_option($option);
23
  if($opt === false)
24
  update_site_option($option, $value);
@@ -26,9 +18,6 @@ class WP_Embed_FB {
26
  }
27
  return;
28
  }
29
- /*
30
- * Delete all plugin options on uninstall
31
- */
32
  static function uninstall(){
33
  $defaults = self::getdefaults();
34
  foreach ($defaults as $option ) {
@@ -40,57 +29,58 @@ class WP_Embed_FB {
40
  }
41
  }
42
  return;
43
- }
44
- /*
45
- * Default options
46
- */
47
  static function getdefaults(){
48
  return array(
49
  'wpemfb_max_width' => '600',
50
  'wpemfb_enqueue_style' => 'true',
 
51
  'wpemfb_app_id' => '0',
52
  'wpemfb_app_secret' => '0',
53
  'wpemfb_proportions' => 0.36867,
54
  'wpemfb_height' => '221.202',
55
  'wpemfb_show_like' => 'true',
56
- 'wpemfb_fb_root' => 'true',
57
- 'wpemfb_theme' => 'default',
58
  );
59
  }
60
- /*
61
- * load translations and facebook sdk
62
- */
63
- static function init(){
64
- load_plugin_textdomain( 'wp-embed-fb', '', WPEMFBLIB.'/lang' );
65
- FaceInit::init();
66
- }
67
- /*
68
- * Enqueue wp embed facebook styles
69
- */
70
  static function wp_enqueue_scripts(){
71
- $theme = get_option('wpemfb_theme');
72
- wp_register_style( 'wpemfb-style', plugins_url('/wp-embed-facebook/templates/'.$theme.'/wpemfb.css'));
73
  wp_enqueue_style( 'wpemfb-style' );
74
  }
75
- /*
76
- * the_content filter to process fb url's
77
- */
78
  static function the_content($the_content){
79
  preg_match_all("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", $the_content, $matches, PREG_SET_ORDER);
80
  if(!empty($matches) && is_array($matches)){
81
  self::$fbsdk = FaceInit::$fbsdk;
82
- if(self::$fbsdk !== 'unactive'){
83
- foreach($matches as $match) {
84
  $the_content = preg_replace("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", self::fb_embed($match), $the_content, 1);
85
- }
86
- }
87
  }
88
- return $the_content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
- /**
91
- * Extract fb_id from the url
92
- * @param array $match[2]=
93
- */
94
  static function fb_embed($match){ //TODO: photos!
95
  $vars = array();
96
  parse_str(parse_url($match[2], PHP_URL_QUERY), $vars);
@@ -109,13 +99,25 @@ class WP_Embed_FB {
109
  $post = $clean[$key +1];
110
  $fb_data = array('user' => $user ,'is_post' => $post);
111
  return self::print_fb_data($fb_data);
112
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  }
114
  return self::fb_api_get($fb_id, $match[2]);
115
  }
116
- /*
117
- * get data from fb using $fbsdk->api('/'.$fb_id) :)
118
- */
119
  static function fb_api_get($fb_id, $url){
120
  $wp_emb_fbsdk = self::$fbsdk;
121
  try {
@@ -124,51 +126,34 @@ class WP_Embed_FB {
124
  $res = self::print_fb_data($fb_data);
125
  } catch(FacebookApiException $e) {
126
  $res = '<p><a href="http://wwww.facebook.com/'.$url.'" target="_blank" rel="nofollow">http://wwww.facebook.com/'.$url.'</a>';
127
- //uncoment this lines to debug
128
- //if(is_super_admin()){
129
- //$res .= '<span style="color: red">'.__('This facebook link is not public', 'wp-embed-fb').'</span></p>';
130
- //$res .= print_r($e->getResult(),true);
131
- //$res .= 'fb_id'.$fb_id;
132
- //}
133
 
134
  }
135
  return $res;
136
  }
137
- /*
138
- * find out what kind of data we got from facebook
139
- */
140
  static function print_fb_data($fb_data){
141
- if(empty(self::$width)){
142
- $width = get_option('wpemfb_max_width');
143
- $height = get_option('wpemfb_height');
144
- } else {
145
- $width = self::$width;
146
- $height = self::$height;
147
- }
148
- $prop = get_option('wpemfb_proportions');
149
  if(isset($fb_data['start_time'])) { //is event
150
  $template = self::locate_template('event');
151
- //} elseif(isset($fb_data['source'])) { //is photo Deprecated by facebook
152
  //$template = self::locate_template('photo');
153
  } elseif(isset($fb_data['category'])) { //is a page
154
  if(isset($fb_data['is_community_page']) && $fb_data['is_community_page'] == "1" ){
155
  $template = self::locate_template('com-page'); //is community page
156
  }else {
157
- $template = self::locate_template('page');
158
- /**
159
- * To add a new template for a fb category add something like this to your functions.php file
160
- *
161
- * add_action( 'wpemfb_category_template', 'your_function', 10, 1 );
162
- * function your_fuction($category) {
163
- * if($category == 'Museum/art gallery'){
164
- * $template = WP_Embed_FB::locate_template('museum')
165
- * }
166
- * }
167
- *
168
- * then create a file named museum.php inside your-theme/plugins/wp-embed-facebook/default/
169
- * remember you can use print_r($fb_data) to see all facebook data.
170
- */
171
- do_action('wpemfb_category_template',$fb_data['category']);
172
  }
173
  } elseif(isset($fb_data['is_post'])) {
174
  $template = self::locate_template('posts');
@@ -178,25 +163,16 @@ class WP_Embed_FB {
178
  $template = self::locate_template('profile');
179
  }
180
  ob_start();
181
- include($template);
182
  return ob_get_clean();
183
  }
184
- /*
185
- * locate the proper template to show the embed
186
- */
187
  static function locate_template($template_name){
188
- $theme = get_option('wpemfb_theme');
189
- $located = locate_template(array('plugins/wp-embed-facebook/'.$theme.'/'.$template_name.'.php'));
190
- if(empty($located))
191
- $located = WPEMFBDIR.'/templates/'.$theme.'/'.$template_name.'.php';
192
  return $located;
193
  }
194
- /*
195
- * Formatting functions.
196
- */
197
- /*
198
- * If a user has a lot of websites registered on fb this function will only link to the first one
199
- */
200
  static function getwebsite($urls){
201
  $url = explode(' ',$urls);
202
  $clean = explode('?', $url[0]);
@@ -204,9 +180,6 @@ class WP_Embed_FB {
204
  $ret = '<a href="http://'.$cleaner.'" title="'.__('Web Site', 'wp-embed-fb').'" target="_blank">'.__('Web Site','wp-embed-fb').'</a>';
205
  return $ret;
206
  }
207
- /*
208
- * Translate fb categories to current locale
209
- */
210
  static function fb_categories($category){
211
  $fbcats = array(
212
  __('Museum/art gallery') ,
@@ -222,74 +195,8 @@ class WP_Embed_FB {
222
  return;
223
  //$replace = array('Museo - Galería de Arte','Negocio Local','Sala de Conciertos','Espacio público');
224
  }
225
- /*
226
- * facebook scripts required to show like buttons and posts added on top of the content
227
- */
228
- static function fb_scripts($the_content){
229
- $opt = get_option('wpemfb_fb_root');
230
- if($opt === 'true'){
231
- ob_start();
232
- ?>
233
- <div id="fb-root"></div>
234
- <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/<?php echo get_locale() ?>/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>
235
- <?php
236
- $scripts = ob_get_clean();
237
- return $scripts.$the_content;
238
- }
239
- return $the_content;
240
- }
241
- /*
242
- * show like buttons or like count
243
- */
244
- static function like_btn($fb_id,$likes=null,$share=false,$faces=false){
245
- $opt = get_option('wpemfb_show_like');
246
- if($opt === 'true') :
247
- ob_start();
248
- ?>
249
- <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' ?>" ></div>
250
- <?php
251
- ob_end_flush();
252
- return;
253
- else :
254
- printf( __( '%d people like this.', 'wp-embed-fb' ), $likes );
255
- return;
256
- endif;
257
- }
258
- /**
259
- * Shotcode function
260
- * [facebook='url' width='600'] width is optional
261
- * @param array [0]=>url ['width']=>embed width
262
- */
263
- static function shortcode($atts){
264
- if(!empty($atts) && isset($atts[0])){
265
- $url = '<p>'.trim($atts[0],'=').'</p>';
266
- if(isset($atts['width'])){
267
- $prop = get_option('wpemfb_proportions');
268
- self::$width = $atts['width'];
269
- self::$height = $prop * $atts['width'];
270
- }
271
- $embed = self::the_content($url);
272
- self::$height = '';
273
- self::$width = '';
274
- self::$theme = '';
275
- return $embed;
276
- }
277
- return;
278
- }
279
- static function shortcode_atts($atts){
280
- if(isset($atts['width'])){
281
- $width = $atts['width'];
282
- $prop = get_option('wpemfb_proportions');
283
- $height = $width * $prop;
284
- }
285
- if(isset($atts['theme']))
286
- $temp = $atts['theme'];
287
- }
288
  }
289
- /*
290
- * Trigering 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
291
- * https://developers.facebook.com/docs/reference/php/
292
- */
293
  class FaceInit {
294
  static $fbsdk;
295
  static function init(){
1
  <?php
 
 
 
2
  class WP_Embed_FB {
3
  static $fbsdk;
4
+ protected static $_values = array();
 
 
 
 
 
5
  static function install(){
6
  $defaults = self::getdefaults();
7
  foreach ($defaults as $option => $value) {
10
  if($opt === false)
11
  update_option($option, $value);
12
  }
13
+ else { // TODO: multiple fb apps for each site
14
  $opt = get_option($option);
15
  if($opt === false)
16
  update_site_option($option, $value);
18
  }
19
  return;
20
  }
 
 
 
21
  static function uninstall(){
22
  $defaults = self::getdefaults();
23
  foreach ($defaults as $option ) {
29
  }
30
  }
31
  return;
32
+ }
 
 
 
33
  static function getdefaults(){
34
  return array(
35
  'wpemfb_max_width' => '600',
36
  'wpemfb_enqueue_style' => 'true',
37
+ //TODO: Quitar esto ponerlo en 0
38
  'wpemfb_app_id' => '0',
39
  'wpemfb_app_secret' => '0',
40
  'wpemfb_proportions' => 0.36867,
41
  'wpemfb_height' => '221.202',
42
  'wpemfb_show_like' => 'true',
 
 
43
  );
44
  }
 
 
 
 
 
 
 
 
 
 
45
  static function wp_enqueue_scripts(){
46
+
47
+ wp_register_style( 'wpemfb-style', plugins_url('../templates/default/wpemfb.css', __FILE__) );
48
  wp_enqueue_style( 'wpemfb-style' );
49
  }
 
 
 
50
  static function the_content($the_content){
51
  preg_match_all("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", $the_content, $matches, PREG_SET_ORDER);
52
  if(!empty($matches) && is_array($matches)){
53
  self::$fbsdk = FaceInit::$fbsdk;
54
+ if(self::$fbsdk !== 'unactive')
55
+ foreach($matches as $match) {
56
  $the_content = preg_replace("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", self::fb_embed($match), $the_content, 1);
57
+ }
 
58
  }
59
+
60
+ return self::fb_scripts().$the_content;
61
+ }
62
+ static function fb_scripts(){
63
+ ob_start();
64
+ ?>
65
+ <div id="fb-root"></div>
66
+ <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/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>
67
+ <?php
68
+ return ob_get_clean();
69
+ }
70
+ static function like_btn($fb_id,$likes=null){
71
+ $opt = get_option('wpemfb_show_like');
72
+ if($opt === 'true') :
73
+ ob_start();
74
+ ?>
75
+ <div class="fb-like" data-href="https://facebook.com/<?php echo $fb_id ?>" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>
76
+ <?php
77
+ ob_end_flush();
78
+ return;
79
+ else :
80
+ printf( __( '%d people like this.', 'wp-embed-fb' ), $likes );
81
+ return;
82
+ endif;
83
  }
 
 
 
 
84
  static function fb_embed($match){ //TODO: photos!
85
  $vars = array();
86
  parse_str(parse_url($match[2], PHP_URL_QUERY), $vars);
99
  $post = $clean[$key +1];
100
  $fb_data = array('user' => $user ,'is_post' => $post);
101
  return self::print_fb_data($fb_data);
102
+ } else {
103
+ $wp_emb_fbsdk = self::$fbsdk;
104
+ try {
105
+ $fb_data = $wp_emb_fbsdk->api('/'.$fb_id);
106
+ //$res = '<pre>'.print_r($fb_data,true).'</pre>'; //to inspect what elements are queried by default
107
+ $res = self::print_fb_data($fb_data);
108
+ } catch(FacebookApiException $e) {
109
+ $res = '<p><a href="http://wwww.facebook.com/'.$match[2].'" target="_blank" rel="nofollow">http://wwww.facebook.com/'.$match[2].'</a><br>';
110
+ if(is_super_admin()){
111
+ $res .= '<span style="color: red">'.__('This facebook link is not public', 'wp-embed-fb').'</span></p>';
112
+ $res .= print_r($e->getResult(),true); //see the problem here
113
+ }
114
+
115
+ }
116
+ return $res;
117
+ }
118
  }
119
  return self::fb_api_get($fb_id, $match[2]);
120
  }
 
 
 
121
  static function fb_api_get($fb_id, $url){
122
  $wp_emb_fbsdk = self::$fbsdk;
123
  try {
126
  $res = self::print_fb_data($fb_data);
127
  } catch(FacebookApiException $e) {
128
  $res = '<p><a href="http://wwww.facebook.com/'.$url.'" target="_blank" rel="nofollow">http://wwww.facebook.com/'.$url.'</a>';
129
+ if(is_super_admin()){
130
+ $res .= '<span style="color: red">'.__('This facebook link is not public', 'wp-embed-fb').'</span></p>';
131
+ $res .= print_r($e->getResult(),true); //see the problem here
132
+ $res .= 'fb_id'.$fb_id;
133
+ }
 
134
 
135
  }
136
  return $res;
137
  }
 
 
 
138
  static function print_fb_data($fb_data){
139
+ $width = get_option('wpemfb_max_width');
140
+ $height = get_option('wpemfb_height');
 
 
 
 
 
 
141
  if(isset($fb_data['start_time'])) { //is event
142
  $template = self::locate_template('event');
143
+ //} elseif(isset($fb_data['source'])) { //is photo Deprecated by facebook now embed post
144
  //$template = self::locate_template('photo');
145
  } elseif(isset($fb_data['category'])) { //is a page
146
  if(isset($fb_data['is_community_page']) && $fb_data['is_community_page'] == "1" ){
147
  $template = self::locate_template('com-page'); //is community page
148
  }else {
149
+ switch ($fb_data['category']) {
150
+ case 'Musician/band': //is a band page
151
+ $template = self::locate_template('band');
152
+ break; //TODO: add action to add more categories
153
+ default:
154
+ $template = self::locate_template('other');
155
+ break;
156
+ }
 
 
 
 
 
 
 
157
  }
158
  } elseif(isset($fb_data['is_post'])) {
159
  $template = self::locate_template('posts');
163
  $template = self::locate_template('profile');
164
  }
165
  ob_start();
166
+ include($template);
167
  return ob_get_clean();
168
  }
 
 
 
169
  static function locate_template($template_name){
170
+ $located = locate_template(array('plugins/wp-embed-facebook/'.$template_name.'.php'));
171
+ if( empty($located) ){
172
+ $located = plugin_dir_path( __FILE__ ).'../templates/default/'.$template_name.'.php';
173
+ }
174
  return $located;
175
  }
 
 
 
 
 
 
176
  static function getwebsite($urls){
177
  $url = explode(' ',$urls);
178
  $clean = explode('?', $url[0]);
180
  $ret = '<a href="http://'.$cleaner.'" title="'.__('Web Site', 'wp-embed-fb').'" target="_blank">'.__('Web Site','wp-embed-fb').'</a>';
181
  return $ret;
182
  }
 
 
 
183
  static function fb_categories($category){
184
  $fbcats = array(
185
  __('Museum/art gallery') ,
195
  return;
196
  //$replace = array('Museo - Galería de Arte','Negocio Local','Sala de Conciertos','Espacio público');
197
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  }
199
+
 
 
 
200
  class FaceInit {
201
  static $fbsdk;
202
  static function init(){
readme.txt CHANGED
@@ -1,74 +1,58 @@
1
  === WP Embed Facebook ===
2
  Contributors: poxtron
3
- Donate link: http://www.saliuitl.org/en/wp-embed-facebook/donate
4
- Tags: facebook, embed, opengraph, fbsdk, facebook events, facebook pages, facebook profiles,
5
- Requires at least: 3.8.1
6
  Tested up to: 3.8.1
7
- Stable tag: 1.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Embed a Facebook page, post, event, photo or profile to any Wordpress post or page.
12
 
13
  == Description ==
14
 
15
- With this plugin you can embed any public facebook page, post, profile, photo or event directly into a wordpress post, without having to write a single line of code. Simply put the facebook url on a separate line on the content of any post, and this plugin will try to fetch data associated with that url and display it on publishing, if the data is not public, like “invite only” events or private profiles, it'll return a link.
16
 
17
  = Supported Embeds =
18
- * Events
 
 
19
  * Fan pages
20
  * Community pages
21
- * Profiles
22
- * Posts
23
- * Photos
24
 
25
  = Requirements =
26
  * Facebook App id and Secret
27
 
28
- = How to use it =
29
- Put on a single and separate line the Facebook URL.
30
-
31
  = Options =
32
  In Settings > Embed Facebook.
33
 
34
  * Change embed width
35
  * Show like buttons on embedded Facebook pages and photos
36
- * Remove plugin styles
37
- * Add fb-root
 
38
 
39
  **[Demo](http://saliuitl.org/en/wp-embed-facebook)**
40
 
41
- * The information that shown on your post, is from facebook directly, no images or data are stored on your server.
 
 
 
42
 
43
  = On the next version =
44
- * Embed Personal Data
45
-
46
  == Installation ==
47
 
48
  1. Download wp embed facebook plugin from [Wordpress](http://wordpress.org/plugins/wp-embed-facebook)
49
- 1. Extract to /wp-content/plugins/ folder, and activate the plugin in /wp-admin/.
50
- 1. Create a [facebook app](https://developers.facebook.com/apps).
51
- 1. Copy the app id and app secret to the “Embed Facebook” page under the Settings section.
52
- 1. Copy on a single line any facebook url.
53
- 1. Enjoy and tell someone !
54
-
55
- == Customisation ==
56
-
57
- 1. Copy the contents of `wp-embed-facebook/templates/default/` to `your-theme/plugins/wp-embed-facebook`
58
- 1. Untick "Enqueue Styles" option to use your own css.
59
- 1. Access all facebook data retrieved from the url using `print_r($fb_data)` on any template file.
60
- 1. Click the taco ! ;)
61
 
62
  == Changelog ==
63
 
64
- = 1.3 =
65
- * Shortcode [facebook=url ] width is optional
66
- * Themes
67
- * Multilingual Like Buttons
68
-
69
- = 1.2.2 =
70
- * Bugs and documentation
71
-
72
  = 1.2.1 =
73
  * Updated Instructions
74
  * Change theme template directory
1
  === WP Embed Facebook ===
2
  Contributors: poxtron
3
+ Donate link: http://www.saliuitl.org/en/wp-embed-facebook
4
+ Tags: facebook, embed, open graph, fbsdk, Facebook events,
5
+ Requires at least: 3.0.1
6
  Tested up to: 3.8.1
7
+ Stable tag: 1.2.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Embed a Facebook page, post, event, photo or profile to any WP post or page.
12
 
13
  == Description ==
14
 
15
+ This plugin embeds public content of a Facebook page directly into a wordpress post.
16
 
17
  = Supported Embeds =
18
+ * Public Posts
19
+ * Public Photos
20
+ * Public Events
21
  * Fan pages
22
  * Community pages
23
+ * Public Profiles
 
 
24
 
25
  = Requirements =
26
  * Facebook App id and Secret
27
 
 
 
 
28
  = Options =
29
  In Settings > Embed Facebook.
30
 
31
  * Change embed width
32
  * Show like buttons on embedded Facebook pages and photos
33
+
34
+ = How to use it =
35
+ Put on a single and separate line the Facebook URL.
36
 
37
  **[Demo](http://saliuitl.org/en/wp-embed-facebook)**
38
 
39
+ = Notes =
40
+ * The information that is shown on your post if from facebook directly, no images or data are stored on your server.
41
+ * You can not embed data that is not public like “invite only” events, or private profiles.
42
+ * To customise de the look of the embeds copy the contents of wp-embed-facebook/templates/default/ to your-theme/plugins/wp-embed-facebook
43
 
44
  = On the next version =
45
+ * Templates
 
46
  == Installation ==
47
 
48
  1. Download wp embed facebook plugin from [Wordpress](http://wordpress.org/plugins/wp-embed-facebook)
49
+ 1. Create a [facebook app](https://developers.facebook.com/apps) and configure for your domain.
50
+ 1. Copy the app id and app secret to the “Embed Facebook” page under the Setting section.
51
+ 1. Put a single
52
+ 1. Enjoy !
 
 
 
 
 
 
 
 
53
 
54
  == Changelog ==
55
 
 
 
 
 
 
 
 
 
56
  = 1.2.1 =
57
  * Updated Instructions
58
  * Change theme template directory
templates/classic/photo.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
- /*
3
- * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
- * to access all fb data print_r($fb_data)
5
- */
6
- ?>
7
- <div class="wpemfb-container">
8
- <div class="wpemfb-info">
9
- <div class="wpemfb-pic">
10
- <img src="http://graph.facebook.com/<?php echo $fb_data['from']['id'] ?>/picture" />
11
- </div>
12
- <div class="wpemfb-desc">
13
- <h4 class="wpemfb-title" >
14
- <a href="https://facebook.com/<?php echo $fb_data['from']['id'] ?>" target="_blank" rel="nofollow">
15
- <?php echo $fb_data['from']['name'] ?>
16
- </a>
17
- </h4>
18
- <?php if(isset($fb_data['from']['category'])) : ?>
19
- <?php WP_Embed_FB::fb_categories($fb_data['from']['category']) ?><br>
20
- <?php endif; ?>
21
- <?php WP_Embed_FB::like_btn($fb_data['id']) ?><br>
22
- </div>
23
- </div>
24
- <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
25
- <img src="<?php echo $fb_data['source'] ?>" width="<?php echo $width ?>" height="auto" />
26
- </a>
27
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/classic/posts.php DELETED
@@ -1,2 +0,0 @@
1
- <div class="fb-post" data-href="https://www.facebook.com/<?php echo $fb_data['user'] ?>/posts/<?php echo $fb_data['is_post'] ?>" data-width="<?php echo $width ?>">
2
- </div>
 
 
templates/default/{page.php → band.php} RENAMED
@@ -3,39 +3,35 @@
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
6
- $width = $width - 20;
7
- $height = $width * $prop;
8
  ?>
9
- <div class="wpemfb-container" style=" width:<?php echo $width ?>px; ">
10
  <div class="wpemfb-pagebk"
11
  style=" height:<?php echo $height ?>px;
12
  width:<?php echo $width?>px;
13
  background-image: url(<?php echo $fb_data['cover']['source'] ?>);
14
  background-position: 0% <?php echo $fb_data['cover']['offset_y'] ?>%;
15
- " onclick="window.open('<?php echo $fb_data['link'] ?>', '_blank')" >
16
 
17
  </div>
18
  <div class="wpemfb-info">
19
  <div class="wpemfb-pic">
20
- <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
21
  <img src="http://graph.facebook.com/<?php echo $fb_data['id'] ?>/picture" />
22
  </a>
23
  </div>
24
  <div class="wpemfb-desc">
25
  <h4 class="wpemfb-title" >
26
- <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
27
  <?php echo $fb_data['name'] ?>
28
  </a>
29
  </h4>
30
- <?php
31
- if($fb_data['category'] == 'Musician/band'){
32
- echo isset($fb_data['genre']) ? $fb_data['genre'].'<br>' : '';
33
- } else {
34
- WP_Embed_FB::fb_categories($fb_data['category']);
35
- }
36
- ?><br>
37
- <div class="fb-btns"><?php WP_Embed_FB::like_btn($fb_data['id'],$fb_data['likes']) ?></div>
38
  <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
39
  </div>
40
  </div>
41
  </div>
 
 
 
 
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
 
 
6
  ?>
7
+ <div class="wpemfb-container" style="min-width:<?php echo $height ?>px">
8
  <div class="wpemfb-pagebk"
9
  style=" height:<?php echo $height ?>px;
10
  width:<?php echo $width?>px;
11
  background-image: url(<?php echo $fb_data['cover']['source'] ?>);
12
  background-position: 0% <?php echo $fb_data['cover']['offset_y'] ?>%;
13
+ ">
14
 
15
  </div>
16
  <div class="wpemfb-info">
17
  <div class="wpemfb-pic">
18
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank">
19
  <img src="http://graph.facebook.com/<?php echo $fb_data['id'] ?>/picture" />
20
  </a>
21
  </div>
22
  <div class="wpemfb-desc">
23
  <h4 class="wpemfb-title" >
24
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank">
25
  <?php echo $fb_data['name'] ?>
26
  </a>
27
  </h4>
28
+ <?php echo isset($fb_data['genre']) ? $fb_data['genre'].'<br>' : '' ?>
29
+ <?php WP_Embed_FB::like_btn($fb_data['id'],$fb_data['likes']) ?><br>
 
 
 
 
 
 
30
  <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
31
  </div>
32
  </div>
33
  </div>
34
+
35
+
36
+
37
+
templates/default/com-page.php CHANGED
@@ -3,10 +3,8 @@
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
6
- $width = $width - 20;
7
- $height = $width * $prop;
8
  ?>
9
- <div class="wpemfb-container">
10
  <div class="wpemfb-info" style="width: <?php echo $width ?>">
11
  <div class="wpemfb-pic">
12
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
 
 
6
  ?>
7
+ <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
8
  <div class="wpemfb-info" style="width: <?php echo $width ?>">
9
  <div class="wpemfb-pic">
10
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
templates/default/event.php CHANGED
@@ -3,14 +3,12 @@
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
6
- $width = $width - 20;
7
- $height = $width * $prop;
8
  ?>
9
  <?php
10
  $start_time_format = !empty($fb_data['is_date_only']) ? '%e %b %Y' : '%e %b %Y %l:%M %P';
11
  $start_time = strtotime($fb_data['start_time']) + get_option('gmt_offset')*3600; //shows event date on local time
12
  ?>
13
- <div class="wpemfb-container">
14
 
15
  <div class="wpemfb-info">
16
  <div class="wpemfb-pic">
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
 
 
6
  ?>
7
  <?php
8
  $start_time_format = !empty($fb_data['is_date_only']) ? '%e %b %Y' : '%e %b %Y %l:%M %P';
9
  $start_time = strtotime($fb_data['start_time']) + get_option('gmt_offset')*3600; //shows event date on local time
10
  ?>
11
+ <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
12
 
13
  <div class="wpemfb-info">
14
  <div class="wpemfb-pic">
templates/{classic/page.php → default/other.php} RENAMED
@@ -29,13 +29,7 @@
29
  <?php echo $fb_data['name'] ?>
30
  </a>
31
  </h4>
32
- <?php
33
- if($fb_data['category'] == 'Musician/band'){
34
- echo isset($fb_data['genre']) ? $fb_data['genre'].'<br>' : '';
35
- } else {
36
- WP_Embed_FB::fb_categories($fb_data['category']);
37
- }
38
- ?><br>
39
  <?php WP_Embed_FB::like_btn($fb_data['id'],$fb_data['likes']) ?><br>
40
  <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
41
  </div>
29
  <?php echo $fb_data['name'] ?>
30
  </a>
31
  </h4>
32
+ <?php WP_Embed_FB::fb_categories($fb_data['category']) ?><br>
 
 
 
 
 
 
33
  <?php WP_Embed_FB::like_btn($fb_data['id'],$fb_data['likes']) ?><br>
34
  <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
35
  </div>
templates/default/photo.php CHANGED
@@ -3,13 +3,12 @@
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
6
- $width = $width - 20;
7
- $height = $width * $prop;
8
  ?>
9
  <div class="wpemfb-container">
10
  <div class="wpemfb-info">
11
  <div class="wpemfb-pic">
12
- <img src="http://graph.facebook.com/<?php echo $fb_data['from']['id'] ?>/picture" />
 
13
  </div>
14
  <div class="wpemfb-desc">
15
  <h4 class="wpemfb-title" >
@@ -26,4 +25,5 @@
26
  <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
27
  <img src="<?php echo $fb_data['source'] ?>" width="<?php echo $width ?>" height="auto" />
28
  </a>
29
- </div>
 
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
 
 
6
  ?>
7
  <div class="wpemfb-container">
8
  <div class="wpemfb-info">
9
  <div class="wpemfb-pic">
10
+ <img src="http://graph.facebook.com/<?php echo $fb_data['from']['id'] ?>/picture" />
11
+ </a>
12
  </div>
13
  <div class="wpemfb-desc">
14
  <h4 class="wpemfb-title" >
25
  <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
26
  <img src="<?php echo $fb_data['source'] ?>" width="<?php echo $width ?>" height="auto" />
27
  </a>
28
+ </div>
29
+ </div>
templates/default/posts.php CHANGED
@@ -1,2 +1,4 @@
1
- <div class="fb-post" data-href="https://www.facebook.com/<?php echo $fb_data['user'] ?>/posts/<?php echo $fb_data['is_post'] ?>" data-width="<?php echo $width ?>">
2
  </div>
 
 
1
+ <div class="fb-post" data-href="https://www.facebook.com/<?php echo $fb_data['user'] ?>/posts/<?php echo $fb_data['is_post'] ?>" data-width="<?php echo $width; ?>">
2
  </div>
3
+
4
+
templates/default/profile.php CHANGED
@@ -3,10 +3,8 @@
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
6
- $width = $width - 20;
7
- $height = $width * $prop;
8
  ?>
9
- <div class="wpemfb-container">
10
  <div class="wpemfb-info">
11
  <div class="wpemfb-pic">
12
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
@@ -16,7 +14,7 @@
16
  <div class="wpemfb-desc">
17
  <h4 class="wpemfb-title" >
18
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
19
- <?php echo $fb_data['name'] ?>
20
  </a>
21
  </h4>
22
  </div>
3
  * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
  * to access all fb data print_r($fb_data)
5
  */
 
 
6
  ?>
7
+ <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
8
  <div class="wpemfb-info">
9
  <div class="wpemfb-pic">
10
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
14
  <div class="wpemfb-desc">
15
  <h4 class="wpemfb-title" >
16
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
17
+ <h3><?php echo $fb_data['name'] ?></h3>
18
  </a>
19
  </h4>
20
  </div>
templates/default/wpemfb.css CHANGED
@@ -1,18 +1,20 @@
 
 
 
1
  .wpemfb-container{
2
- border: 1px solid #DEDEDE;
 
3
  border-radius: 2px;
 
4
  display: inline-table;
5
- font-family: Helvetica;
6
  height: auto;
7
- margin: 5px auto;
8
- padding: 10px;
9
  }
10
  .wpemfb-pagebk{
11
  background-size: 100%;
12
- cursor: pointer;
13
  }
14
  .wpemfb-info a {
15
- font-family: Helvetica;
16
  color: #23487E;
17
  text-decoration: none !important;
18
  }
@@ -35,6 +37,4 @@
35
  display: table-cell;
36
  vertical-align: middle;
37
  }
38
- .fb-btns {
39
- float: right;
40
- }
1
+ .wpemfb-dummy {
2
+ padding-top: 80%;
3
+ }
4
  .wpemfb-container{
5
+ margin-top:5px;
6
+ border: 1px solid #23487E;
7
  border-radius: 2px;
8
+ box-shadow: 2px 2px 3px #1A3151;
9
  display: inline-table;
 
10
  height: auto;
11
+ margin-left: auto ;
12
+ margin-right: auto ;
13
  }
14
  .wpemfb-pagebk{
15
  background-size: 100%;
 
16
  }
17
  .wpemfb-info a {
 
18
  color: #23487E;
19
  text-decoration: none !important;
20
  }
37
  display: table-cell;
38
  vertical-align: middle;
39
  }
40
+
 
 
trunk/lang/.pot.pot ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: wp-embed-fb\n"
4
+ "POT-Creation-Date: 2014-02-26 10:48-0600\n"
5
+ "PO-Revision-Date: 2014-02-26 10:51-0600\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: \n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.6.4\n"
12
+ "X-Poedit-Basepath: .\n"
13
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
+ "Language: en_US\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
trunk/lang/wp-embed-fb-es_ES.mo ADDED
Binary file
trunk/lang/wp-embed-fb-es_ES.po ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: wp-embed-fb\n"
4
+ "POT-Creation-Date: 2014-02-26 18:53-0600\n"
5
+ "PO-Revision-Date: 2014-02-26 19:06-0600\n"
6
+ "Last-Translator: Miguel Sirvent <miguel.sirvent@gmail.com>\n"
7
+ "Language-Team: Miguel Sirvent <miguel.sirvent@gmail.com>\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.6.4\n"
12
+ "X-Poedit-Basepath: .\n"
13
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-KeywordsList: __;_e\n"
16
+ "Language: es_ES\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: ../lib/admin.php:67
20
+ msgid "Facebook application data"
21
+ msgstr "Datos de la aplicación de Facebook."
22
+
23
+ #: ../lib/admin.php:84
24
+ msgid "Other Options"
25
+ msgstr "Otras Opciones"
26
+
27
+ #: ../lib/admin.php:90
28
+ msgid "Fb Cover Embed Width"
29
+ msgstr "Ancho máximo del Embed"
30
+
31
+ #: ../lib/admin.php:96
32
+ msgid "Enqueue Styles"
33
+ msgstr "Incluir css del plugin"
34
+
35
+ #: ../lib/admin.php:104
36
+ msgid "Save"
37
+ msgstr "Guardar"
38
+
39
+ #: ../lib/admin.php:112
40
+ msgid "Customize"
41
+ msgstr "Customizar"
42
+
43
+ #: ../lib/admin.php:115
44
+ msgid "Support"
45
+ msgstr "Soporte"
46
+
47
+ #: ../lib/admin.php:118
48
+ msgid "Plugin Web Site"
49
+ msgstr "Sitio Web del plugin"
50
+
51
+ #: ../lib/admin.php:126
52
+ msgid "Donate!"
53
+ msgstr "Dona !"
54
+
55
+ #: ../lib/admin.php:127
56
+ msgid "Help me keep this plugin up to date"
57
+ msgstr "Ayúdame a manter este plugin actualizado"
58
+
59
+ #: ../lib/admin.php:129
60
+ msgid "Click the taco !"
61
+ msgstr "Click en el taco !"
62
+
63
+ #: ../lib/admin.php:130
64
+ msgid "3 USD Minimun Suggested Donation"
65
+ msgstr "Mínimo Sugerido 3 USD"
66
+
67
+ #: ../lib/admin.php:140
68
+ msgid "Searching for the Premium version ?"
69
+ msgstr "Buscando la versión premium ?"
70
+
71
+ #: ../lib/admin.php:143
72
+ msgid "Custom templates"
73
+ msgstr "Templates personalizados"
74
+
75
+ #: ../lib/admin.php:146
76
+ msgid "Compatibility with all themes imaginable"
77
+ msgstr "Compatibilidad con todos los themes imaginables"
78
+
79
+ #: ../lib/admin.php:149
80
+ msgid "Multiple fb app id's per each multisite site"
81
+ msgstr "Multiples app's en multisite"
82
+
83
+ #: ../lib/admin.php:152
84
+ msgid "Comming Soon"
85
+ msgstr "Pronto muy pronto"
86
+
87
+ #: ../lib/core.php:84
88
+ msgid "Something is wrong with this link"
89
+ msgstr "Algo le pasa a este link"
90
+
91
+ #: ../lib/core.php:127
92
+ msgid "Web Site"
93
+ msgstr "Sitio Web"
94
+
95
+ #: ../lib/core.php:132
96
+ msgid "Museum/art gallery"
97
+ msgstr "Museo / Galería de Arte"
98
+
99
+ #: ../lib/core.php:133
100
+ msgid "Local business"
101
+ msgstr "Negocio Local"
102
+
103
+ #: ../lib/core.php:134
104
+ msgid "Concert venue"
105
+ msgstr "Foro de Conciertos"
106
+
107
+ #: ../lib/core.php:135
108
+ msgid "Public places"
109
+ msgstr "Lugar publico"
110
+
111
+ #: ../templates/default/band.php:25 ../templates/default/com-page.php:16
112
+ #: ../templates/default/other.php:25
113
+ #, php-format
114
+ msgid "%d people like this."
115
+ msgstr "a %d les gusta esto."
116
+
117
+ #: ../templates/default/event.php:17
118
+ msgid "d M Y"
119
+ msgstr ""
120
+
121
+ #: ../templates/default/event.php:17
122
+ msgid "d M Y g:ia"
123
+ msgstr ""
124
+
125
+ #: ../templates/default/event.php:43
126
+ msgid "Creator: "
127
+ msgstr "Creador:"
trunk/lang/wp-embed-fb.mo ADDED
Binary file
trunk/lang/wp-embed-fb.pot ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: wp-embed-fb\n"
4
+ "POT-Creation-Date: 2014-02-26 18:53-0600\n"
5
+ "PO-Revision-Date: 2014-02-26 18:53-0600\n"
6
+ "Last-Translator: \n"
7
+ "Language-Team: Miguel Sirvent <miguel.sirvent@gmail.com>\n"
8
+ "Language: en_US\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.4\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-KeywordsList: __;_e\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: ../lib/admin.php:67
20
+ msgid "Facebook application data"
21
+ msgstr ""
22
+
23
+ #: ../lib/admin.php:84
24
+ msgid "Other Options"
25
+ msgstr ""
26
+
27
+ #: ../lib/admin.php:90
28
+ msgid "Fb Cover Embed Width"
29
+ msgstr ""
30
+
31
+ #: ../lib/admin.php:96
32
+ msgid "Enqueue Styles"
33
+ msgstr ""
34
+
35
+ #: ../lib/admin.php:104
36
+ msgid "Save"
37
+ msgstr ""
38
+
39
+ #: ../lib/admin.php:112
40
+ msgid "Customize"
41
+ msgstr ""
42
+
43
+ #: ../lib/admin.php:115
44
+ msgid "Support"
45
+ msgstr ""
46
+
47
+ #: ../lib/admin.php:118
48
+ msgid "Plugin Web Site"
49
+ msgstr ""
50
+
51
+ #: ../lib/admin.php:126
52
+ msgid "Donate!"
53
+ msgstr ""
54
+
55
+ #: ../lib/admin.php:127
56
+ msgid "Help me keep this plugin up to date"
57
+ msgstr ""
58
+
59
+ #: ../lib/admin.php:129
60
+ msgid "Click the taco !"
61
+ msgstr ""
62
+
63
+ #: ../lib/admin.php:130
64
+ msgid "3 USD Minimun Suggested Donation"
65
+ msgstr ""
66
+
67
+ #: ../lib/admin.php:140
68
+ msgid "Searching for the Premium version ?"
69
+ msgstr ""
70
+
71
+ #: ../lib/admin.php:143
72
+ msgid "Custom templates"
73
+ msgstr ""
74
+
75
+ #: ../lib/admin.php:146
76
+ msgid "Compatibility with all themes imaginable"
77
+ msgstr ""
78
+
79
+ #: ../lib/admin.php:149
80
+ msgid "Multiple fb app id's per each multisite site"
81
+ msgstr ""
82
+
83
+ #: ../lib/admin.php:152
84
+ msgid "Comming Soon"
85
+ msgstr ""
86
+
87
+ #: ../lib/core.php:84
88
+ msgid "Something is wrong with this link"
89
+ msgstr ""
90
+
91
+ #: ../lib/core.php:127
92
+ msgid "Web Site"
93
+ msgstr ""
94
+
95
+ #: ../lib/core.php:132
96
+ msgid "Museum/art gallery"
97
+ msgstr ""
98
+
99
+ #: ../lib/core.php:133
100
+ msgid "Local business"
101
+ msgstr ""
102
+
103
+ #: ../lib/core.php:134
104
+ msgid "Concert venue"
105
+ msgstr ""
106
+
107
+ #: ../lib/core.php:135
108
+ msgid "Public places"
109
+ msgstr ""
110
+
111
+ #: ../templates/default/band.php:25 ../templates/default/com-page.php:16
112
+ #: ../templates/default/other.php:25
113
+ #, php-format
114
+ msgid "%d people like this."
115
+ msgstr ""
116
+
117
+ #: ../templates/default/event.php:17
118
+ msgid "d M Y"
119
+ msgstr ""
120
+
121
+ #: ../templates/default/event.php:17
122
+ msgid "d M Y g:ia"
123
+ msgstr ""
124
+
125
+ #: ../templates/default/event.php:43
126
+ msgid "Creator: "
127
+ msgstr ""
trunk/lib/admin.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class EmbFbAdmin{
3
+ static function add_page(){
4
+ add_options_page('EmbedFacebook', 'Embed Facebook', 'manage_options', 'embedfacebook', array('EmbFbAdmin', 'embedfb_page'));
5
+ }
6
+ static function savedata(){
7
+ //if ( !empty($_POST) && check_admin_referer('wp-embed-fb','nonce') )
8
+ if(isset($_POST['appsecret'], $_POST['appid' ] )) {
9
+ $wpemfb_width = get_option('wpemfb_max_width');
10
+ $proportions = get_option('wpemfb_proportions');
11
+
12
+ if($_POST['appid'] && $_POST['appsecret']){
13
+ if ( !is_multisite() ) {
14
+ update_option('wpemfb_app_id',$_POST['appid']);
15
+ update_option('wpemfb_app_secret',$_POST['appsecret']);
16
+ }
17
+ else { // TODO: multiple fb apps for each site
18
+ update_site_option('wpemfb_app_id',$_POST['appid']);
19
+ update_site_option('wpemfb_app_secret',$_POST['appsecret']);
20
+ }
21
+ }
22
+ if(isset($_POST['max-width'])){
23
+ $prop = get_option('wpemfb_proportions') * $_POST['max-width'];
24
+ if ( !is_multisite() ) {
25
+ update_option('wpemfb_max_width', $_POST['max-width']);
26
+ update_option('wpemfb_height', $prop );
27
+ }
28
+ else { // TODO: multiple fb apps for each site
29
+ update_site_option('wpemfb_max_width', $_POST['max-width']);
30
+ update_site_option('wpemfb_height', $prop);
31
+ }
32
+ }
33
+ if(isset($_POST['wpemfb_enqueue_style'])){
34
+ if ( !is_multisite() )
35
+ update_option('wpemfb_enqueue_style', 'true');
36
+ else // TODO: multiple fb apps for each site
37
+ update_site_option('wpemfb_enqueue_style', 'true');
38
+ }else{
39
+ if ( !is_multisite() ) {
40
+ update_option('wpemfb_enqueue_style', 'false');
41
+ }
42
+ else { // TODO: multiple fb apps for each site
43
+ update_site_option('wpemfb_enqueue_style', 'false');
44
+ }
45
+ }
46
+ }
47
+
48
+ }
49
+ static function embedfb_page() {
50
+ //global $new_emb_fbsdk; //TODO: eliminate this test
51
+ if(isset($_POST['submit'])){
52
+ self::savedata();
53
+ }
54
+ $style = get_option('wpemfb_enqueue_style');
55
+ $checked = ($style === 'true') ? 'checked' : '' ;
56
+ ?>
57
+ <div class="wrap">
58
+ <h2>WP Embed Facebook</h2>
59
+ <div class="welcome-panel">
60
+ <div class="welcome-panel-content">
61
+ <div class="welcome-panel-column-container">
62
+ <div class="welcome-panel-column">
63
+ <form id="config-form" action="#" method="post">
64
+ <table class="form-table">
65
+ <tbody>
66
+ <tr>
67
+ <h3><?php _e('Facebook application data', 'wp-embed-fb') ?></h3>
68
+ </tr>
69
+ <tr valign="middle">
70
+ <th>App ID</th>
71
+ <td>
72
+ <input type="text" name="appid" id="appid" class="input" required="" value="<?php echo get_option('wpemfb_app_id') ?>" />
73
+ </td>
74
+ </tr>
75
+ <tr valign="middle">
76
+ <th>App Secret</th>
77
+ <td>
78
+ <input type="text" name="appsecret" id="appsecret" class="input" required="" value="<?php echo get_option('wpemfb_app_secret') ?>" />
79
+ </td>
80
+ </tr>
81
+ <tr>
82
+ <th>
83
+ <td>
84
+ <h4><?php _e("Other Options", 'wp-embed-fb') ?></h4>
85
+ </td>
86
+
87
+ </th>
88
+ </tr>
89
+ <tr valign="middle">
90
+ <th><?php _e('Fb Cover Embed Width','wp-embed-fb') ?></th>
91
+ <td>
92
+ <input type="text" name="max-width" id="max-width" class="input" value="<?php echo get_option('wpemfb_max_width') ?>" /
93
+ </td>
94
+ </tr>
95
+ <tr valign="middle">
96
+ <th><?php _e('Enqueue Styles','wp-embed-fb') ?></th>
97
+ <td>
98
+ <input type="checkbox" name="wpemfb_enqueue_style" <?php echo $checked ?> /><br>
99
+ </td>
100
+ </tr>
101
+ <tr>
102
+ <td>
103
+ <?php //echo wp_nonce_field('wpebfb','nonce'); ?>
104
+ <input type="submit" name="submit" id="save-config" class="button button-primary button-hero" value="<?php _e('Save','wp-embed-fb') ?>" />
105
+ </td>
106
+ </tr>
107
+ </tbody>
108
+ </table>
109
+ </form
110
+ <ul class="">
111
+ <li>
112
+ <a href="http://www.saliuitl.org/wp-embed-fb/customize"><?php _e('Customize','wp-embed-fb') ?></a>
113
+ </li>
114
+ <li>
115
+ <a href="http://www.saliuitl.org/wp-embed-fb/support"><?php _e('Support','wp-embed-fb') ?></a>
116
+ </li>
117
+ <li>
118
+ <a href="http://www.saliuitl.org/wp-embed-fb"><?php _e('Plugin Web Site','wp-embed-fb') ?></a>
119
+ </li>
120
+ </ul>
121
+ </div>
122
+ <div class="welcome-panel-column">
123
+ <p></p>
124
+ </div>
125
+ <div class="welcome-panel-column welcome-panel-last">
126
+ <h3 style="color:red;"><?php _e('Donate!', 'wp-embed-fb') ?></h3>
127
+ <p><?php _e('Help me keep this plugin up to date', 'wp-embed-fb') ?></p>
128
+ <p>
129
+ <strong><?php _e('Click the taco !', 'wp-embed-fb') ?></strong><br>
130
+ <small><?php _e('3 USD Minimun Suggested Donation', 'wp-embed-fb') ?></small>
131
+ </p>
132
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
133
+ <input type="hidden" name="cmd" value="_s-xclick">
134
+ <input type="hidden" name="hosted_button_id" value="9TEJ8CGXMJEDG">
135
+ <input type="image" src="http://saliuitl.org/img/taco.png" border="0" name="submit" alt="PayPal, la forma más segura y rápida de pagar en línea.">
136
+ <img alt="" border="0" src="https://www.paypalobjects.com/es_XC/i/scr/pixel.gif" width="1" height="1">
137
+ </form>
138
+ <img src="<?php echo plugins_url('/img/paypal.png', __FILE__) ?>" width="50px" />
139
+ <p>
140
+ <h3 style="color:red;"><?php _e('Searching for the Premium version ?', 'wp-embed-fb') ?></h3>
141
+ <ul>
142
+ <li>
143
+ <?php _e('Custom templates', 'wp-embed-fb') ?>
144
+ </li>
145
+ <li>
146
+ <?php _e('Compatibility with all themes imaginable', 'wp-embed-fb') ?>
147
+ </li>
148
+ <li>
149
+ <?php _e("Multiple fb app id's per each multisite site", 'wp-embed-fb') ?>
150
+ </li>
151
+ </ul>
152
+ <h4 style="color:#01007E;"><?php _e('Comming Soon', 'wp-embed-fb') ?></h4>
153
+ </p>
154
+ <p style="text-align: center">
155
+ <img src="<?php echo plugins_url('/img/hechoenmexico.png', __FILE__) ?>" width="80px" />
156
+ </p>
157
+
158
+ </div>
159
+ <!-- <div class="welcome-panel-column welcome-panel-last"> -->
160
+ </div>
161
+ </div>
162
+ </div>
163
+ </div><!-- .wrap -->
164
+
165
+
166
+ <?php
167
+ }
168
+ }
169
+ ?>
trunk/lib/core.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class WP_Embed_FB {
3
+ static $fbsdk;
4
+ protected static $_values = array();
5
+ static function install(){
6
+ $defaults = self::getdefaults();
7
+ foreach ($defaults as $option => $value) {
8
+ if ( !is_multisite() ) {
9
+ $opt = get_option($option);
10
+ if($opt === false)
11
+ update_option($option, $value);
12
+ }
13
+ else { // TODO: multiple fb apps for each site
14
+ $opt = get_option($option);
15
+ if($opt === false)
16
+ update_site_option($option, $value);
17
+ }
18
+ }
19
+ return;
20
+ }
21
+ static function uninstall(){
22
+ $defaults = self::getdefaults();
23
+ foreach ($defaults as $option ) {
24
+ if ( !is_multisite() ) {
25
+ delete_option($option);
26
+ }
27
+ else { // TODO: multiple fb apps for each site
28
+ delete_site_option($option);
29
+ }
30
+ }
31
+ return;
32
+ }
33
+ static function getdefaults(){
34
+ return array(
35
+ 'wpemfb_max_width' => '600',
36
+ 'wpemfb_enqueue_style' => 'true',
37
+ //TODO: Quitar esto ponerlo en 0
38
+ 'wpemfb_app_id' => '0',
39
+ 'wpemfb_app_secret' => '0',
40
+ 'wpemfb_proportions' => 0.36867,
41
+ 'wpemfb_height' => '221.202',
42
+ );
43
+ }
44
+ static function wp_enqueue_scripts(){
45
+
46
+ wp_register_style( 'wpemfb-style', plugins_url('../templates/default/wpemfb.css', __FILE__) );
47
+ wp_enqueue_style( 'wpemfb-style' );
48
+ }
49
+ static function the_content($the_content){
50
+ preg_match_all("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", $the_content, $matches, PREG_SET_ORDER);
51
+ if(!empty($matches) && is_array($matches)){
52
+ self::$fbsdk = FaceInit::$fbsdk;
53
+ if(self::$fbsdk !== 'unactive')
54
+ foreach($matches as $match) {
55
+ $the_content = preg_replace("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", self::fb_embed($match), $the_content, 1);
56
+ }
57
+ }
58
+
59
+ return $the_content;
60
+ }
61
+ static function fb_embed($match){ //TODO: photos!
62
+ $wp_emb_fbsdk = self::$fbsdk;
63
+ $vars = array();
64
+ parse_str(parse_url($match[2], PHP_URL_QUERY), $vars);
65
+ if(isset($vars['fbid'])){ //for photos deprecated by fb
66
+ $fb_id = $vars['fbid'];
67
+ } else {
68
+ $url = explode('?', $match[2]);
69
+ $clean = explode('/', $url[0]);
70
+ $last = end($clean);
71
+ if( empty( $last ) )
72
+ $fb_id = $clean[count($clean)-2];//penultimo valor
73
+ else
74
+ $fb_id = $last;
75
+ }
76
+ //echo $fb_id.'<br>';
77
+ try {
78
+ $fb_data = $wp_emb_fbsdk->api('/'.$fb_id);
79
+ //$res = '<pre>'.print_r($fb_data,true).'</pre>'; //to inspect what elements are queried by default
80
+ $res = self::print_fb_data($fb_data);
81
+ } catch(FacebookApiException $e) {
82
+ $res = '<p><a href="http://wwww.facebook.com/'.$match[2].'" target="_blank" rel="nofollow">http://wwww.facebook.com/'.$match[2].'</a>';
83
+ if(is_super_admin()){
84
+ $res .= '<span style="color: red">'.__('Something is wrong with this link', 'wp-embed-fb').'</span></p>';
85
+ $res .= print_r($e->getResult(),true); //see the problem here
86
+ }
87
+
88
+ }
89
+ return $res;
90
+ }
91
+ static function print_fb_data($fb_data){
92
+ $width = get_option('wpemfb_max_width');
93
+ $height = get_option('wpemfb_height');
94
+ if(isset($fb_data['start_time'])) { //is event
95
+ $template = self::locate_template('event');
96
+ //} elseif(isset($fb_data['source'])) { //is photo Deprecated by facebook now embed post
97
+ //$template = self::locate_template('photo');
98
+ } elseif(isset($fb_data['category'])) { //is a page
99
+ if(isset($fb_data['is_community_page']) && $fb_data['is_community_page'] == "1" ){
100
+ $template = self::locate_template('com-page'); //is community page
101
+ }else {
102
+ switch ($fb_data['category']) {
103
+ case 'Musician/band': //is a band page
104
+ $template = self::locate_template('band');
105
+ break; //TODO: add action to add more categories
106
+ default:
107
+ $template = self::locate_template('other');
108
+ break;
109
+ }
110
+ }
111
+ } else { //is profile
112
+ $template = self::locate_template('profile');
113
+ }
114
+ ob_start();
115
+ include($template);
116
+ return ob_get_clean();
117
+ }
118
+ static function locate_template($template_name){
119
+ $located = locate_template(array('plugins/wp-embed-fb/'.$template_name.'.php'));
120
+ if( empty($located) ){
121
+ $located = plugin_dir_path( __FILE__ ).'../templates/default/'.$template_name.'.php';
122
+ }
123
+ return $located;
124
+ }
125
+ static function getwebsite($urls){
126
+ $url = explode(' ',$urls);
127
+ $clean = explode('?', $url[0]);
128
+ $cleaner = str_replace(array('http://', 'https://'), array('',''), $clean[0]);
129
+ $ret = '<a href="http://'.$cleaner.'" title="'.__('Web Site', 'wp-embed-fb').'" target="_blank">'.__('Web Site','wp-embed-fb').'</a>';
130
+ return $ret;
131
+ }
132
+ static function fb_categories($category){
133
+ $fbcats = array(
134
+ __('Museum/art gallery') ,
135
+ __('Local business'),
136
+ __('Concert venue'),
137
+ __('Public places'),
138
+ );
139
+ //$catsflip = array_flip($fbcats); TODO: Translate categories
140
+ if($id = array_search($category, $fbcats) !== false)
141
+ return $fbcats[$id];
142
+ else
143
+ return (string)$category;
144
+ //$replace = array('Museo - Galería de Arte','Negocio Local','Sala de Conciertos','Espacio público');
145
+ }
146
+ }
147
+
148
+ class FaceInit {
149
+ static $fbsdk;
150
+ static function init(){
151
+ if(!class_exists('Facebook'))
152
+ require('fb/facebook.php');
153
+ $config = array();
154
+ $config['appId'] = get_option('wpemfb_app_id');
155
+ $config['secret'] = get_option('wpemfb_app_secret');
156
+ $config['fileUpload'] = false; // optional
157
+ if($config['appId'] != '0' && $config['secret'] != '0' )
158
+ self::$fbsdk = new Facebook($config);
159
+ else
160
+ self::$fbsdk = 'unactive';
161
+ }
162
+ }
163
+ ?>
trunk/lib/fb/base_facebook.php ADDED
@@ -0,0 +1,1427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2011 Facebook, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ if (!function_exists('curl_init')) {
19
+ throw new Exception('Facebook needs the CURL PHP extension.');
20
+ }
21
+ if (!function_exists('json_decode')) {
22
+ throw new Exception('Facebook needs the JSON PHP extension.');
23
+ }
24
+
25
+ /**
26
+ * Thrown when an API call returns an exception.
27
+ *
28
+ * @author Naitik Shah <naitik@facebook.com>
29
+ */
30
+ class FacebookApiException extends Exception
31
+ {
32
+ /**
33
+ * The result from the API server that represents the exception information.
34
+ */
35
+ protected $result;
36
+
37
+ /**
38
+ * Make a new API Exception with the given result.
39
+ *
40
+ * @param array $result The result from the API server
41
+ */
42
+ public function __construct($result) {
43
+ $this->result = $result;
44
+
45
+ $code = isset($result['error_code']) ? $result['error_code'] : 0;
46
+
47
+ if (isset($result['error_description'])) {
48
+ // OAuth 2.0 Draft 10 style
49
+ $msg = $result['error_description'];
50
+ } else if (isset($result['error']) && is_array($result['error'])) {
51
+ // OAuth 2.0 Draft 00 style
52
+ $msg = $result['error']['message'];
53
+ } else if (isset($result['error_msg'])) {
54
+ // Rest server style
55
+ $msg = $result['error_msg'];
56
+ } else {
57
+ $msg = 'Unknown Error. Check getResult()';
58
+ }
59
+
60
+ parent::__construct($msg, $code);
61
+ }
62
+
63
+ /**
64
+ * Return the associated result object returned by the API server.
65
+ *
66
+ * @return array The result from the API server
67
+ */
68
+ public function getResult() {
69
+ return $this->result;
70
+ }
71
+
72
+ /**
73
+ * Returns the associated type for the error. This will default to
74
+ * 'Exception' when a type is not available.
75
+ *
76
+ * @return string
77
+ */
78
+ public function getType() {
79
+ if (isset($this->result['error'])) {
80
+ $error = $this->result['error'];
81
+ if (is_string($error)) {
82
+ // OAuth 2.0 Draft 10 style
83
+ return $error;
84
+ } else if (is_array($error)) {
85
+ // OAuth 2.0 Draft 00 style
86
+ if (isset($error['type'])) {
87
+ return $error['type'];
88
+ }
89
+ }
90
+ }
91
+
92
+ return 'Exception';
93
+ }
94
+
95
+ /**
96
+ * To make debugging easier.
97
+ *
98
+ * @return string The string representation of the error
99
+ */
100
+ public function __toString() {
101
+ $str = $this->getType() . ': ';
102
+ if ($this->code != 0) {
103
+ $str .= $this->code . ': ';
104
+ }
105
+ return $str . $this->message;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Provides access to the Facebook Platform. This class provides
111
+ * a majority of the functionality needed, but the class is abstract
112
+ * because it is designed to be sub-classed. The subclass must
113
+ * implement the four abstract methods listed at the bottom of
114
+ * the file.
115
+ *
116
+ * @author Naitik Shah <naitik@facebook.com>
117
+ */
118
+ abstract class BaseFacebook
119
+ {
120
+ /**
121
+ * Version.
122
+ */
123
+ const VERSION = '3.2.0';
124
+
125
+ /**
126
+ * Signed Request Algorithm.
127
+ */
128
+ const SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256';
129
+
130
+ /**
131
+ * Default options for curl.
132
+ */
133
+ public static $CURL_OPTS = array(
134
+ CURLOPT_CONNECTTIMEOUT => 10,
135
+ CURLOPT_RETURNTRANSFER => true,
136
+ CURLOPT_TIMEOUT => 60,
137
+ CURLOPT_USERAGENT => 'facebook-php-3.2',
138
+ );
139
+
140
+ /**
141
+ * List of query parameters that get automatically dropped when rebuilding
142
+ * the current URL.
143
+ */
144
+ protected static $DROP_QUERY_PARAMS = array(
145
+ 'code',
146
+ 'state',
147
+ 'signed_request',
148
+ );
149
+
150
+ /**
151
+ * Maps aliases to Facebook domains.
152
+ */
153
+ public static $DOMAIN_MAP = array(
154
+ 'api' => 'https://api.facebook.com/',
155
+ 'api_video' => 'https://api-video.facebook.com/',
156
+ 'api_read' => 'https://api-read.facebook.com/',
157
+ 'graph' => 'https://graph.facebook.com/',
158
+ 'graph_video' => 'https://graph-video.facebook.com/',
159
+ 'www' => 'https://www.facebook.com/',
160
+ );
161
+
162
+ /**
163
+ * The Application ID.
164
+ *
165
+ * @var string
166
+ */
167
+ protected $appId;
168
+
169
+ /**
170
+ * The Application App Secret.
171
+ *
172
+ * @var string
173
+ */
174
+ protected $appSecret;
175
+
176
+ /**
177
+ * The ID of the Facebook user, or 0 if the user is logged out.
178
+ *
179
+ * @var integer
180
+ */
181
+ protected $user;
182
+
183
+ /**
184
+ * The data from the signed_request token.
185
+ */
186
+ protected $signedRequest;
187
+
188
+ /**
189
+ * A CSRF state variable to assist in the defense against CSRF attacks.
190
+ */
191
+ protected $state;
192
+
193
+ /**
194
+ * The OAuth access token received in exchange for a valid authorization
195
+ * code. null means the access token has yet to be determined.
196
+ *
197
+ * @var string
198
+ */
199
+ protected $accessToken = null;
200
+
201
+ /**
202
+ * Indicates if the CURL based @ syntax for file uploads is enabled.
203
+ *
204
+ * @var boolean
205
+ */
206
+ protected $fileUploadSupport = false;
207
+
208
+ /**
209
+ * Indicates if we trust HTTP_X_FORWARDED_* headers.
210
+ *
211
+ * @var boolean
212
+ */
213
+ protected $trustForwarded = false;
214
+
215
+ /**
216
+ * Initialize a Facebook Application.
217
+ *
218
+ * The configuration:
219
+ * - appId: the application ID
220
+ * - secret: the application secret
221
+ * - fileUpload: (optional) boolean indicating if file uploads are enabled
222
+ *
223
+ * @param array $config The application configuration
224
+ */
225
+ public function __construct($config) {
226
+ $this->setAppId($config['appId']);
227
+ $this->setAppSecret($config['secret']);
228
+ if (isset($config['fileUpload'])) {
229
+ $this->setFileUploadSupport($config['fileUpload']);
230
+ }
231
+ if (isset($config['trustForwarded']) && $config['trustForwarded']) {
232
+ $this->trustForwarded = true;
233
+ }
234
+ $state = $this->getPersistentData('state');
235
+ if (!empty($state)) {
236
+ $this->state = $state;
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Set the Application ID.
242
+ *
243
+ * @param string $appId The Application ID
244
+ * @return BaseFacebook
245
+ */
246
+ public function setAppId($appId) {
247
+ $this->appId = $appId;
248
+ return $this;
249
+ }
250
+
251
+ /**
252
+ * Get the Application ID.
253
+ *
254
+ * @return string the Application ID
255
+ */
256
+ public function getAppId() {
257
+ return $this->appId;
258
+ }
259
+
260
+ /**
261
+ * Set the App Secret.
262
+ *
263
+ * @param string $apiSecret The App Secret
264
+ * @return BaseFacebook
265
+ * @deprecated
266
+ */
267
+ public function setApiSecret($apiSecret) {
268
+ $this->setAppSecret($apiSecret);
269
+ return $this;
270
+ }
271
+
272
+ /**
273
+ * Set the App Secret.
274
+ *
275
+ * @param string $appSecret The App Secret
276
+ * @return BaseFacebook
277
+ */
278
+ public function setAppSecret($appSecret) {
279
+ $this->appSecret = $appSecret;
280
+ return $this;
281
+ }
282
+
283
+ /**
284
+ * Get the App Secret.
285
+ *
286
+ * @return string the App Secret
287
+ * @deprecated
288
+ */
289
+ public function getApiSecret() {
290
+ return $this->getAppSecret();
291
+ }
292
+
293
+ /**
294
+ * Get the App Secret.
295
+ *
296
+ * @return string the App Secret
297
+ */
298
+ public function getAppSecret() {
299
+ return $this->appSecret;
300
+ }
301
+
302
+ /**
303
+ * Set the file upload support status.
304
+ *
305
+ * @param boolean $fileUploadSupport The file upload support status.
306
+ * @return BaseFacebook
307
+ */
308
+ public function setFileUploadSupport($fileUploadSupport) {
309
+ $this->fileUploadSupport = $fileUploadSupport;
310
+ return $this;
311
+ }
312
+
313
+ /**
314
+ * Get the file upload support status.
315
+ *
316
+ * @return boolean true if and only if the server supports file upload.
317
+ */
318
+ public function getFileUploadSupport() {
319
+ return $this->fileUploadSupport;
320
+ }
321
+
322
+ /**
323
+ * DEPRECATED! Please use getFileUploadSupport instead.
324
+ *
325
+ * Get the file upload support status.
326
+ *
327
+ * @return boolean true if and only if the server supports file upload.
328
+ */
329
+ public function useFileUploadSupport() {
330
+ return $this->getFileUploadSupport();
331
+ }
332
+
333
+ /**
334
+ * Sets the access token for api calls. Use this if you get
335
+ * your access token by other means and just want the SDK
336
+ * to use it.
337
+ *
338
+ * @param string $access_token an access token.
339
+ * @return BaseFacebook
340
+ */
341
+ public function setAccessToken($access_token) {
342
+ $this->accessToken = $access_token;
343
+ return $this;
344
+ }
345
+
346
+ /**
347
+ * Extend an access token, while removing the short-lived token that might
348
+ * have been generated via client-side flow. Thanks to http://bit.ly/b0Pt0H
349
+ * for the workaround.
350
+ */
351
+ public function setExtendedAccessToken() {
352
+ try {
353
+ // need to circumvent json_decode by calling _oauthRequest
354
+ // directly, since response isn't JSON format.
355
+ $access_token_response = $this->_oauthRequest(
356
+ $this->getUrl('graph', '/oauth/access_token'),
357
+ $params = array(
358
+ 'client_id' => $this->getAppId(),
359
+ 'client_secret' => $this->getAppSecret(),
360
+ 'grant_type' => 'fb_exchange_token',
361
+ 'fb_exchange_token' => $this->getAccessToken(),
362
+ )
363
+ );
364
+ }
365
+ catch (FacebookApiException $e) {
366
+ // most likely that user very recently revoked authorization.
367
+ // In any event, we don't have an access token, so say so.
368
+ return false;
369
+ }
370
+
371
+ if (empty($access_token_response)) {
372
+ return false;
373
+ }
374
+
375
+ $response_params = array();
376
+ parse_str($access_token_response, $response_params);
377
+
378
+ if (!isset($response_params['access_token'])) {
379
+ return false;
380
+ }
381
+
382
+ $this->destroySession();
383
+
384
+ $this->setPersistentData(
385
+ 'access_token', $response_params['access_token']
386
+ );
387
+ }
388
+
389
+ /**
390
+ * Determines the access token that should be used for API calls.
391
+ * The first time this is called, $this->accessToken is set equal
392
+ * to either a valid user access token, or it's set to the application
393
+ * access token if a valid user access token wasn't available. Subsequent
394
+ * calls return whatever the first call returned.
395
+ *
396
+ * @return string The access token
397
+ */
398
+ public function getAccessToken() {
399
+ if ($this->accessToken !== null) {
400
+ // we've done this already and cached it. Just return.
401
+ return $this->accessToken;
402
+ }
403
+
404
+ // first establish access token to be the application
405
+ // access token, in case we navigate to the /oauth/access_token
406
+ // endpoint, where SOME access token is required.
407
+ $this->setAccessToken($this->getApplicationAccessToken());
408
+ $user_access_token = $this->getUserAccessToken();
409
+ if ($user_access_token) {
410
+ $this->setAccessToken($user_access_token);
411
+ }
412
+
413
+ return $this->accessToken;
414
+ }
415
+
416
+ /**
417
+ * Determines and returns the user access token, first using
418
+ * the signed request if present, and then falling back on
419
+ * the authorization code if present. The intent is to
420
+ * return a valid user access token, or false if one is determined
421
+ * to not be available.
422
+ *
423
+ * @return string A valid user access token, or false if one
424
+ * could not be determined.
425
+ */
426
+ protected function getUserAccessToken() {
427
+ // first, consider a signed request if it's supplied.
428
+ // if there is a signed request, then it alone determines
429
+ // the access token.
430
+ $signed_request = $this->getSignedRequest();
431
+ if ($signed_request) {
432
+ // apps.facebook.com hands the access_token in the signed_request
433
+ if (array_key_exists('oauth_token', $signed_request)) {
434
+ $access_token = $signed_request['oauth_token'];
435
+ $this->setPersistentData('access_token', $access_token);
436
+ return $access_token;
437
+ }
438
+
439
+ // the JS SDK puts a code in with the redirect_uri of ''
440
+ if (array_key_exists('code', $signed_request)) {
441
+ $code = $signed_request['code'];
442
+ $access_token = $this->getAccessTokenFromCode($code, '');
443
+ if ($access_token) {
444
+ $this->setPersistentData('code', $code);
445
+ $this->setPersistentData('access_token', $access_token);
446
+ return $access_token;
447
+ }
448
+ }
449
+
450
+ // signed request states there's no access token, so anything
451
+ // stored should be cleared.
452
+ $this->clearAllPersistentData();
453
+ return false; // respect the signed request's data, even
454
+ // if there's an authorization code or something else
455
+ }
456
+
457
+ $code = $this->getCode();
458
+ if ($code && $code != $this->getPersistentData('code')) {
459
+ $access_token = $this->getAccessTokenFromCode($code);
460
+ if ($access_token) {
461
+ $this->setPersistentData('code', $code);
462
+ $this->setPersistentData('access_token', $access_token);
463
+ return $access_token;
464
+ }
465
+
466
+ // code was bogus, so everything based on it should be invalidated.
467
+ $this->clearAllPersistentData();
468
+ return false;
469
+ }
470
+
471
+ // as a fallback, just return whatever is in the persistent
472
+ // store, knowing nothing explicit (signed request, authorization
473
+ // code, etc.) was present to shadow it (or we saw a code in $_REQUEST,
474
+ // but it's the same as what's in the persistent store)
475
+ return $this->getPersistentData('access_token');
476
+ }
477
+
478
+ /**
479
+ * Retrieve the signed request, either from a request parameter or,
480
+ * if not present, from a cookie.
481
+ *
482
+ * @return string the signed request, if available, or null otherwise.
483
+ */
484
+ public function getSignedRequest() {
485
+ if (!$this->signedRequest) {
486
+ if (isset($_REQUEST['signed_request'])) {
487
+ $this->signedRequest = $this->parseSignedRequest(
488
+ $_REQUEST['signed_request']);
489
+ } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
490
+ $this->signedRequest = $this->parseSignedRequest(
491
+ $_COOKIE[$this->getSignedRequestCookieName()]);
492
+ }
493
+ }
494
+ return $this->signedRequest;
495
+ }
496
+
497
+ /**
498
+ * Get the UID of the connected user, or 0
499
+ * if the Facebook user is not connected.
500
+ *
501
+ * @return string the UID if available.
502
+ */
503
+ public function getUser() {
504
+ if ($this->user !== null) {
505
+ // we've already determined this and cached the value.
506
+ return $this->user;
507
+ }
508
+
509
+ return $this->user = $this->getUserFromAvailableData();
510
+ }
511
+
512
+ /**
513
+ * Determines the connected user by first examining any signed
514
+ * requests, then considering an authorization code, and then
515
+ * falling back to any persistent store storing the user.
516
+ *
517
+ * @return integer The id of the connected Facebook user,
518
+ * or 0 if no such user exists.
519
+ */
520
+ protected function getUserFromAvailableData() {
521
+ // if a signed request is supplied, then it solely determines
522
+ // who the user is.
523
+ $signed_request = $this->getSignedRequest();
524
+ if ($signed_request) {
525
+ if (array_key_exists('user_id', $signed_request)) {
526
+ $user = $signed_request['user_id'];
527
+ $this->setPersistentData('user_id', $signed_request['user_id']);
528
+ return $user;
529
+ }
530
+
531
+ // if the signed request didn't present a user id, then invalidate
532
+ // all entries in any persistent store.
533
+ $this->clearAllPersistentData();
534
+ return 0;
535
+ }
536
+
537
+ $user = $this->getPersistentData('user_id', $default = 0);
538
+ $persisted_access_token = $this->getPersistentData('access_token');
539
+
540
+ // use access_token to fetch user id if we have a user access_token, or if
541
+ // the cached access token has changed.
542
+ $access_token = $this->getAccessToken();
543
+ if ($access_token &&
544
+ $access_token != $this->getApplicationAccessToken() &&
545
+ !($user && $persisted_access_token == $access_token)) {
546
+ $user = $this->getUserFromAccessToken();
547
+ if ($user) {
548
+ $this->setPersistentData('user_id', $user);
549
+ } else {
550
+ $this->clearAllPersistentData();
551
+ }
552
+ }
553
+
554
+ return $user;
555
+ }
556
+
557
+ /**
558
+ * Get a Login URL for use with redirects. By default, full page redirect is
559
+ * assumed. If you are using the generated URL with a window.open() call in
560
+ * JavaScript, you can pass in display=popup as part of the $params.
561
+ *
562
+ * The parameters:
563
+ * - redirect_uri: the url to go to after a successful login
564
+ * - scope: comma separated list of requested extended perms
565
+ *
566
+ * @param array $params Provide custom parameters
567
+ * @return string The URL for the login flow
568
+ */
569
+ public function getLoginUrl($params=array()) {
570
+ $this->establishCSRFTokenState();
571
+ $currentUrl = $this->getCurrentUrl();
572
+
573
+ // if 'scope' is passed as an array, convert to comma separated list
574
+ $scopeParams = isset($params['scope']) ? $params['scope'] : null;
575
+ if ($scopeParams && is_array($scopeParams)) {
576
+ $params['scope'] = implode(',', $scopeParams);
577
+ }
578
+
579
+ return $this->getUrl(
580
+ 'www',
581
+ 'dialog/oauth',
582
+ array_merge(array(
583
+ 'client_id' => $this->getAppId(),
584
+ 'redirect_uri' => $currentUrl, // possibly overwritten
585
+ 'state' => $this->state),
586
+ $params));
587
+ }
588
+
589
+ /**
590
+ * Get a Logout URL suitable for use with redirects.
591
+ *
592
+ * The parameters:
593
+ * - next: the url to go to after a successful logout
594
+ *
595
+ * @param array $params Provide custom parameters
596
+ * @return string The URL for the logout flow
597
+ */
598
+ public function getLogoutUrl($params=array()) {
599
+ return $this->getUrl(
600
+ 'www',
601
+ 'logout.php',
602
+ array_merge(array(
603
+ 'next' => $this->getCurrentUrl(),
604
+ 'access_token' => $this->getUserAccessToken(),
605
+ ), $params)
606
+ );
607
+ }
608
+
609
+ /**
610
+ * Get a login status URL to fetch the status from Facebook.
611
+ *
612
+ * The parameters:
613
+ * - ok_session: the URL to go to if a session is found
614
+ * - no_session: the URL to go to if the user is not connected
615
+ * - no_user: the URL to go to if the user is not signed into facebook
616
+ *
617
+ * @param array $params Provide custom parameters
618
+ * @return string The URL for the logout flow
619
+ */
620
+ public function getLoginStatusUrl($params=array()) {
621
+ return $this->getUrl(
622
+ 'www',
623
+ 'extern/login_status.php',
624
+ array_merge(array(
625
+ 'api_key' => $this->getAppId(),
626
+ 'no_session' => $this->getCurrentUrl(),
627
+ 'no_user' => $this->getCurrentUrl(),
628
+ 'ok_session' => $this->getCurrentUrl(),
629
+ 'session_version' => 3,
630
+ ), $params)
631
+ );
632
+ }
633
+
634
+ /**
635
+ * Make an API call.
636
+ *
637
+ * @return mixed The decoded response
638
+ */
639
+ public function api(/* polymorphic */) {
640
+ $args = func_get_args();
641
+ if (is_array($args[0])) {
642
+ return $this->_restserver($args[0]);
643
+ } else {
644
+ return call_user_func_array(array($this, '_graph'), $args);
645
+ }
646
+ }
647
+
648
+ /**
649
+ * Constructs and returns the name of the cookie that
650
+ * potentially houses the signed request for the app user.
651
+ * The cookie is not set by the BaseFacebook class, but
652
+ * it may be set by the JavaScript SDK.
653
+ *
654
+ * @return string the name of the cookie that would house
655
+ * the signed request value.
656
+ */
657
+ protected function getSignedRequestCookieName() {
658
+ return 'fbsr_'.$this->getAppId();
659
+ }
660
+
661
+ /**
662
+ * Constructs and returns the name of the coookie that potentially contain
663
+ * metadata. The cookie is not set by the BaseFacebook class, but it may be
664
+ * set by the JavaScript SDK.
665
+ *
666
+ * @return string the name of the cookie that would house metadata.
667
+ */
668
+ protected function getMetadataCookieName() {
669
+ return 'fbm_'.$this->getAppId();
670
+ }
671
+
672
+ /**
673
+ * Get the authorization code from the query parameters, if it exists,
674
+ * and otherwise return false to signal no authorization code was
675
+ * discoverable.
676
+ *
677
+ * @return mixed The authorization code, or false if the authorization
678
+ * code could not be determined.
679
+ */
680
+ protected function getCode() {
681
+ if (isset($_REQUEST['code'])) {
682
+ if ($this->state !== null &&
683
+ isset($_REQUEST['state']) &&
684
+ $this->state === $_REQUEST['state']) {
685
+
686
+ // CSRF state has done its job, so clear it
687
+ $this->state = null;
688
+ $this->clearPersistentData('state');
689
+ return $_REQUEST['code'];
690
+ } else {
691
+ self::errorLog('CSRF state token does not match one provided.');
692
+ return false;
693
+ }
694
+ }
695
+
696
+ return false;
697
+ }
698
+
699
+ /**
700
+ * Retrieves the UID with the understanding that
701
+ * $this->accessToken has already been set and is
702
+ * seemingly legitimate. It relies on Facebook's Graph API
703
+ * to retrieve user information and then extract
704
+ * the user ID.
705
+ *
706
+ * @return integer Returns the UID of the Facebook user, or 0
707
+ * if the Facebook user could not be determined.
708
+ */
709
+ protected function getUserFromAccessToken() {
710
+ try {
711
+ $user_info = $this->api('/me');
712
+ return $user_info['id'];
713
+ } catch (FacebookApiException $e) {
714
+ return 0;
715
+ }
716
+ }
717
+
718
+ /**
719
+ * Returns the access token that should be used for logged out
720
+ * users when no authorization code is available.
721
+ *
722
+ * @return string The application access token, useful for gathering
723
+ * public information about users and applications.
724
+ */
725
+ protected function getApplicationAccessToken() {
726
+ return $this->appId.'|'.$this->appSecret;
727
+ }
728
+
729
+ /**
730
+ * Lays down a CSRF state token for this process.
731
+ *
732
+ * @return void
733
+ */
734
+ protected function establishCSRFTokenState() {
735
+ if ($this->state === null) {
736
+ $this->state = md5(uniqid(mt_rand(), true));
737
+ $this->setPersistentData('state', $this->state);
738
+ }
739
+ }
740
+
741
+ /**
742
+ * Retrieves an access token for the given authorization code
743
+ * (previously generated from www.facebook.com on behalf of
744
+ * a specific user). The authorization code is sent to graph.facebook.com
745
+ * and a legitimate access token is generated provided the access token
746
+ * and the user for which it was generated all match, and the user is
747
+ * either logged in to Facebook or has granted an offline access permission.
748
+ *
749
+ * @param string $code An authorization code.
750
+ * @return mixed An access token exchanged for the authorization code, or
751
+ * false if an access token could not be generated.
752
+ */
753
+ protected function getAccessTokenFromCode($code, $redirect_uri = null) {
754
+ if (empty($code)) {
755
+ return false;
756
+ }
757
+
758
+ if ($redirect_uri === null) {
759
+ $redirect_uri = $this->getCurrentUrl();
760
+ }
761
+
762
+ try {
763
+ // need to circumvent json_decode by calling _oauthRequest
764
+ // directly, since response isn't JSON format.
765
+ $access_token_response =
766
+ $this->_oauthRequest(
767
+ $this->getUrl('graph', '/oauth/access_token'),
768
+ $params = array('client_id' => $this->getAppId(),
769
+ 'client_secret' => $this->getAppSecret(),
770
+ 'redirect_uri' => $redirect_uri,
771
+ 'code' => $code));
772
+ } catch (FacebookApiException $e) {
773
+ // most likely that user very recently revoked authorization.
774
+ // In any event, we don't have an access token, so say so.
775
+ return false;
776
+ }
777
+
778
+ if (empty($access_token_response)) {
779
+ return false;
780
+ }
781
+
782
+ $response_params = array();
783
+ parse_str($access_token_response, $response_params);
784
+ if (!isset($response_params['access_token'])) {
785
+ return false;
786
+ }
787
+
788
+ return $response_params['access_token'];
789
+ }
790
+
791
+ /**
792
+ * Invoke the old restserver.php endpoint.
793
+ *
794
+ * @param array $params Method call object
795
+ *
796
+ * @return mixed The decoded response object
797
+ * @throws FacebookApiException
798
+ */
799
+ protected function _restserver($params) {
800
+ // generic application level parameters
801
+ $params['api_key'] = $this->getAppId();
802
+ $params['format'] = 'json-strings';
803
+
804
+ $result = json_decode($this->_oauthRequest(
805
+ $this->getApiUrl($params['method']),
806
+ $params
807
+ ), true);
808
+
809
+ // results are returned, errors are thrown
810
+ if (is_array($result) && isset($result['error_code'])) {
811
+ $this->throwAPIException($result);
812
+ // @codeCoverageIgnoreStart
813
+ }
814
+ // @codeCoverageIgnoreEnd
815
+
816
+ $method = strtolower($params['method']);
817
+ if ($method === 'auth.expiresession' ||
818
+ $method === 'auth.revokeauthorization') {
819
+ $this->destroySession();
820
+ }
821
+
822
+ return $result;
823
+ }
824
+
825
+ /**
826
+ * Return true if this is video post.
827
+ *
828
+ * @param string $path The path
829
+ * @param string $method The http method (default 'GET')
830
+ *
831
+ * @return boolean true if this is video post
832
+ */
833
+ protected function isVideoPost($path, $method = 'GET') {
834
+ if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) {
835
+ return true;
836
+ }
837
+ return false;
838
+ }
839
+
840
+ /**
841
+ * Invoke the Graph API.
842
+ *
843
+ * @param string $path The path (required)
844
+ * @param string $method The http method (default 'GET')
845
+ * @param array $params The query/post data
846
+ *
847
+ * @return mixed The decoded response object
848
+ * @throws FacebookApiException
849
+ */
850
+ protected function _graph($path, $method = 'GET', $params = array()) {
851
+ if (is_array($method) && empty($params)) {
852
+ $params = $method;
853
+ $method = 'GET';
854
+ }
855
+ $params['method'] = $method; // method override as we always do a POST
856
+
857
+ if ($this->isVideoPost($path, $method)) {
858
+ $domainKey = 'graph_video';
859
+ } else {
860
+ $domainKey = 'graph';
861
+ }
862
+
863
+ $result = json_decode($this->_oauthRequest(
864
+ $this->getUrl($domainKey, $path),
865
+ $params
866
+ ), true);
867
+
868
+ // results are returned, errors are thrown
869
+ if (is_array($result) && isset($result['error'])) {
870
+ $this->throwAPIException($result);
871
+ // @codeCoverageIgnoreStart
872
+ }
873
+ // @codeCoverageIgnoreEnd
874
+
875
+ return $result;
876
+ }
877
+
878
+ /**
879
+ * Make a OAuth Request.
880
+ *
881
+ * @param string $url The path (required)
882
+ * @param array $params The query/post data
883
+ *
884
+ * @return string The decoded response object
885
+ * @throws FacebookApiException
886
+ */
887
+ protected function _oauthRequest($url, $params) {
888
+ if (!isset($params['access_token'])) {
889
+ $params['access_token'] = $this->getAccessToken();
890
+ }
891
+
892
+ // json_encode all params values that are not strings
893
+ foreach ($params as $key => $value) {
894
+ if (!is_string($value)) {
895
+ $params[$key] = json_encode($value);
896
+ }
897
+ }
898
+
899
+ return $this->makeRequest($url, $params);
900
+ }
901
+
902
+ /**
903
+ * Makes an HTTP request. This method can be overridden by subclasses if
904
+ * developers want to do fancier things or use something other than curl to
905
+ * make the request.
906
+ *
907
+ * @param string $url The URL to make the request to
908
+ * @param array $params The parameters to use for the POST body
909
+ * @param CurlHandler $ch Initialized curl handle
910
+ *
911
+ * @return string The response text
912
+ */
913
+ protected function makeRequest($url, $params, $ch=null) {
914
+ if (!$ch) {
915
+ $ch = curl_init();
916
+ }
917
+
918
+ $opts = self::$CURL_OPTS;
919
+ if ($this->getFileUploadSupport()) {
920
+ $opts[CURLOPT_POSTFIELDS] = $params;
921
+ } else {
922
+ $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
923
+ }
924
+ $opts[CURLOPT_URL] = $url;
925
+
926
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
927
+ // for 2 seconds if the server does not support this header.
928
+ if (isset($opts[CURLOPT_HTTPHEADER])) {
929
+ $existing_headers = $opts[CURLOPT_HTTPHEADER];
930
+ $existing_headers[] = 'Expect:';
931
+ $opts[CURLOPT_HTTPHEADER] = $existing_headers;
932
+ } else {
933
+ $opts[CURLOPT_HTTPHEADER] = array('Expect:');
934
+ }
935
+ //no ssl verification xz3 modifications
936
+ $opts[CURLOPT_SSL_VERIFYPEER] = false;
937
+ //end modifications
938
+ curl_setopt_array($ch, $opts);
939
+ $result = curl_exec($ch);
940
+
941
+ if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
942
+ self::errorLog('Invalid or no certificate authority found, '.
943
+ 'using bundled information');
944
+ curl_setopt($ch, CURLOPT_CAINFO,
945
+ dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
946
+ $result = curl_exec($ch);
947
+ }
948
+
949
+ // With dual stacked DNS responses, it's possible for a server to
950
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
951
+ // the case, curl will try IPv4 first and if that fails, then it will
952
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
953
+ // operating system.
954
+ if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
955
+ $matches = array();
956
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
957
+ if (preg_match($regex, curl_error($ch), $matches)) {
958
+ if (strlen(@inet_pton($matches[1])) === 16) {
959
+ self::errorLog('Invalid IPv6 configuration on server, '.
960
+ 'Please disable or get native IPv6 on your server.');
961
+ self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
962
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
963
+ $result = curl_exec($ch);
964
+ }
965
+ }
966
+ }
967
+
968
+ if ($result === false) {
969
+ $e = new FacebookApiException(array(
970
+ 'error_code' => curl_errno($ch),
971
+ 'error' => array(
972
+ 'message' => curl_error($ch),
973
+ 'type' => 'CurlException',
974
+ ),
975
+ ));
976
+ curl_close($ch);
977
+ throw $e;
978
+ }
979
+ curl_close($ch);
980
+ return $result;
981
+ }
982
+
983
+ /**
984
+ * Parses a signed_request and validates the signature.
985
+ *
986
+ * @param string $signed_request A signed token
987
+ * @return array The payload inside it or null if the sig is wrong
988
+ */
989
+ protected function parseSignedRequest($signed_request) {
990
+ list($encoded_sig, $payload) = explode('.', $signed_request, 2);
991
+
992
+ // decode the data
993
+ $sig = self::base64UrlDecode($encoded_sig);
994
+ $data = json_decode(self::base64UrlDecode($payload), true);
995
+
996
+ if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) {
997
+ self::errorLog(
998
+ 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM);
999
+ return null;
1000
+ }
1001
+
1002
+ // check sig
1003
+ $expected_sig = hash_hmac('sha256', $payload,
1004
+ $this->getAppSecret(), $raw = true);
1005
+ if ($sig !== $expected_sig) {
1006
+ self::errorLog('Bad Signed JSON signature!');
1007
+ return null;
1008
+ }
1009
+
1010
+ return $data;
1011
+ }
1012
+
1013
+ /**
1014
+ * Makes a signed_request blob using the given data.
1015
+ *
1016
+ * @param array The data array.
1017
+ * @return string The signed request.
1018
+ */
1019
+ protected function makeSignedRequest($data) {
1020
+ if (!is_array($data)) {
1021
+ throw new InvalidArgumentException(
1022
+ 'makeSignedRequest expects an array. Got: ' . print_r($data, true));
1023
+ }
1024
+ $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
1025
+ $data['issued_at'] = time();
1026
+ $json = json_encode($data);
1027
+ $b64 = self::base64UrlEncode($json);
1028
+ $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
1029
+ $sig = self::base64UrlEncode($raw_sig);
1030
+ return $sig.'.'.$b64;
1031
+ }
1032
+
1033
+ /**
1034
+ * Build the URL for api given parameters.
1035
+ *
1036
+ * @param $method String the method name.
1037
+ * @return string The URL for the given parameters
1038
+ */
1039
+ protected function getApiUrl($method) {
1040
+ static $READ_ONLY_CALLS =
1041
+ array('admin.getallocation' => 1,
1042
+ 'admin.getappproperties' => 1,
1043
+ 'admin.getbannedusers' => 1,
1044
+ 'admin.getlivestreamvialink' => 1,
1045
+ 'admin.getmetrics' => 1,
1046
+ 'admin.getrestrictioninfo' => 1,
1047
+ 'application.getpublicinfo' => 1,
1048
+ 'auth.getapppublickey' => 1,
1049
+ 'auth.getsession' => 1,
1050
+ 'auth.getsignedpublicsessiondata' => 1,
1051
+ 'comments.get' => 1,
1052
+ 'connect.getunconnectedfriendscount' => 1,
1053
+ 'dashboard.getactivity' => 1,
1054
+ 'dashboard.getcount' => 1,
1055
+ 'dashboard.getglobalnews' => 1,
1056
+ 'dashboard.getnews' => 1,
1057
+ 'dashboard.multigetcount' => 1,
1058
+ 'dashboard.multigetnews' => 1,
1059
+ 'data.getcookies' => 1,
1060
+ 'events.get' => 1,
1061
+ 'events.getmembers' => 1,
1062
+ 'fbml.getcustomtags' => 1,
1063
+ 'feed.getappfriendstories' => 1,
1064
+ 'feed.getregisteredtemplatebundlebyid' => 1,
1065
+ 'feed.getregisteredtemplatebundles' => 1,
1066
+ 'fql.multiquery' => 1,
1067
+ 'fql.query' => 1,
1068
+ 'friends.arefriends' => 1,
1069
+ 'friends.get' => 1,
1070
+ 'friends.getappusers' => 1,
1071
+ 'friends.getlists' => 1,
1072
+ 'friends.getmutualfriends' => 1,
1073
+ 'gifts.get' => 1,
1074
+ 'groups.get' => 1,
1075
+ 'groups.getmembers' => 1,
1076
+ 'intl.gettranslations' => 1,
1077
+ 'links.get' => 1,
1078
+ 'notes.get' => 1,
1079
+ 'notifications.get' => 1,
1080
+ 'pages.getinfo' => 1,
1081
+ 'pages.isadmin' => 1,
1082
+ 'pages.isappadded' => 1,
1083
+ 'pages.isfan' => 1,
1084
+ 'permissions.checkavailableapiaccess' => 1,
1085
+ 'permissions.checkgrantedapiaccess' => 1,
1086
+ 'photos.get' => 1,
1087
+ 'photos.getalbums' => 1,
1088
+ 'photos.gettags' => 1,
1089
+ 'profile.getinfo' => 1,
1090
+ 'profile.getinfooptions' => 1,
1091
+ 'stream.get' => 1,
1092
+ 'stream.getcomments' => 1,
1093
+ 'stream.getfilters' => 1,
1094
+ 'users.getinfo' => 1,
1095
+ 'users.getloggedinuser' => 1,
1096
+ 'users.getstandardinfo' => 1,
1097
+ 'users.hasapppermission' => 1,
1098
+ 'users.isappuser' => 1,
1099
+ 'users.isverified' => 1,
1100
+ 'video.getuploadlimits' => 1);
1101
+ $name = 'api';
1102
+ if (isset($READ_ONLY_CALLS[strtolower($method)])) {
1103
+ $name = 'api_read';
1104
+ } else if (strtolower($method) == 'video.upload') {
1105
+ $name = 'api_video';
1106
+ }
1107
+ return self::getUrl($name, 'restserver.php');
1108
+ }
1109
+
1110
+ /**
1111
+ * Build the URL for given domain alias, path and parameters.
1112
+ *
1113
+ * @param $name string The name of the domain
1114
+ * @param $path string Optional path (without a leading slash)
1115
+ * @param $params array Optional query parameters
1116
+ *
1117
+ * @return string The URL for the given parameters
1118
+ */
1119
+ protected function getUrl($name, $path='', $params=array()) {
1120
+ $url = self::$DOMAIN_MAP[$name];
1121
+ if ($path) {
1122
+ if ($path[0] === '/') {
1123
+ $path = substr($path, 1);
1124
+ }
1125
+ $url .= $path;
1126
+ }
1127
+ if ($params) {
1128
+ $url .= '?' . http_build_query($params, null, '&');
1129
+ }
1130
+
1131
+ return $url;
1132
+ }
1133
+
1134
+ protected function getHttpHost() {
1135
+ if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
1136
+ return $_SERVER['HTTP_X_FORWARDED_HOST'];
1137
+ }
1138
+ return $_SERVER['HTTP_HOST'];
1139
+ }
1140
+
1141
+ protected function getHttpProtocol() {
1142
+ if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
1143
+ if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
1144
+ return 'https';
1145
+ }
1146
+ return 'http';
1147
+ }
1148
+ if (isset($_SERVER['HTTPS']) &&
1149
+ ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
1150
+ return 'https';
1151
+ }
1152
+ return 'http';
1153
+ }
1154
+
1155
+ /**
1156
+ * Get the base domain used for the cookie.
1157
+ */
1158
+ protected function getBaseDomain() {
1159
+ // The base domain is stored in the metadata cookie if not we fallback
1160
+ // to the current hostname
1161
+ $metadata = $this->getMetadataCookie();
1162
+ if (array_key_exists('base_domain', $metadata) &&
1163
+ !empty($metadata['base_domain'])) {
1164
+ return trim($metadata['base_domain'], '.');
1165
+ }
1166
+ return $this->getHttpHost();
1167
+ }
1168
+
1169
+ /**
1170
+
1171
+ /**
1172
+ * Returns the Current URL, stripping it of known FB parameters that should
1173
+ * not persist.
1174
+ *
1175
+ * @return string The current URL
1176
+ */
1177
+ protected function getCurrentUrl() {
1178
+ $protocol = $this->getHttpProtocol() . '://';
1179
+ $host = $this->getHttpHost();
1180
+ $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI'];
1181
+ $parts = parse_url($currentUrl);
1182
+
1183
+ $query = '';
1184
+ if (!empty($parts['query'])) {
1185
+ // drop known fb params
1186
+ $params = explode('&', $parts['query']);
1187
+ $retained_params = array();
1188
+ foreach ($params as $param) {
1189
+ if ($this->shouldRetainParam($param)) {
1190
+ $retained_params[] = $param;
1191
+ }
1192
+ }
1193
+
1194
+ if (!empty($retained_params)) {
1195
+ $query = '?'.implode($retained_params, '&');
1196
+ }
1197
+ }
1198
+
1199
+ // use port if non default
1200
+ $port =
1201
+ isset($parts['port']) &&
1202
+ (($protocol === 'http://' && $parts['port'] !== 80) ||
1203
+ ($protocol === 'https://' && $parts['port'] !== 443))
1204
+ ? ':' . $parts['port'] : '';
1205
+
1206
+ // rebuild
1207
+ return $protocol . $parts['host'] . $port . $parts['path'] . $query;
1208
+ }
1209
+
1210
+ /**
1211
+ * Returns true if and only if the key or key/value pair should
1212
+ * be retained as part of the query string. This amounts to
1213
+ * a brute-force search of the very small list of Facebook-specific
1214
+ * params that should be stripped out.
1215
+ *
1216
+ * @param string $param A key or key/value pair within a URL's query (e.g.
1217
+ * 'foo=a', 'foo=', or 'foo'.
1218
+ *
1219
+ * @return boolean
1220
+ */
1221
+ protected function shouldRetainParam($param) {
1222
+ foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
1223
+ if (strpos($param, $drop_query_param.'=') === 0) {
1224
+ return false;
1225
+ }
1226
+ }
1227
+
1228
+ return true;
1229
+ }
1230
+
1231
+ /**
1232
+ * Analyzes the supplied result to see if it was thrown
1233
+ * because the access token is no longer valid. If that is
1234
+ * the case, then we destroy the session.
1235
+ *
1236
+ * @param $result array A record storing the error message returned
1237
+ * by a failed API call.
1238
+ */
1239
+ protected function throwAPIException($result) {
1240
+ $e = new FacebookApiException($result);
1241
+ switch ($e->getType()) {
1242
+ // OAuth 2.0 Draft 00 style
1243
+ case 'OAuthException':
1244
+ // OAuth 2.0 Draft 10 style
1245
+ case 'invalid_token':
1246
+ // REST server errors are just Exceptions
1247
+ case 'Exception':
1248
+ $message = $e->getMessage();
1249
+ if ((strpos($message, 'Error validating access token') !== false) ||
1250
+ (strpos($message, 'Invalid OAuth access token') !== false) ||
1251
+ (strpos($message, 'An active access token must be used') !== false)
1252
+ ) {
1253
+ $this->destroySession();
1254
+ }
1255
+ break;
1256
+ }
1257
+
1258
+ throw $e;
1259
+ }
1260
+
1261
+
1262
+ /**
1263
+ * Prints to the error log if you aren't in command line mode.
1264
+ *
1265
+ * @param string $msg Log message
1266
+ */
1267
+ protected static function errorLog($msg) {
1268
+ // disable error log if we are running in a CLI environment
1269
+ // @codeCoverageIgnoreStart
1270
+ if (php_sapi_name() != 'cli') {
1271
+ error_log($msg);
1272
+ }
1273
+ // uncomment this if you want to see the errors on the page
1274
+ // print 'error_log: '.$msg."\n";
1275
+ // @codeCoverageIgnoreEnd
1276
+ }
1277
+
1278
+ /**
1279
+ * Base64 encoding that doesn't need to be urlencode()ed.
1280
+ * Exactly the same as base64_encode except it uses
1281
+ * - instead of +
1282
+ * _ instead of /
1283
+ * No padded =
1284
+ *
1285
+ * @param string $input base64UrlEncoded string
1286
+ * @return string
1287
+ */
1288
+ protected static function base64UrlDecode($input) {
1289
+ return base64_decode(strtr($input, '-_', '+/'));
1290
+ }
1291
+
1292
+ /**
1293
+ * Base64 encoding that doesn't need to be urlencode()ed.
1294
+ * Exactly the same as base64_encode except it uses
1295
+ * - instead of +
1296
+ * _ instead of /
1297
+ *
1298
+ * @param string $input string
1299
+ * @return string base64Url encoded string
1300
+ */
1301
+ protected static function base64UrlEncode($input) {
1302
+ $str = strtr(base64_encode($input), '+/', '-_');
1303
+ $str = str_replace('=', '', $str);
1304
+ return $str;
1305
+ }
1306
+
1307
+ /**
1308
+ * Destroy the current session
1309
+ */
1310
+ public function destroySession() {
1311
+ $this->accessToken = null;
1312
+ $this->signedRequest = null;
1313
+ $this->user = null;
1314
+ $this->clearAllPersistentData();
1315
+
1316
+ // Javascript sets a cookie that will be used in getSignedRequest that we
1317
+ // need to clear if we can
1318
+ $cookie_name = $this->getSignedRequestCookieName();
1319
+ if (array_key_exists($cookie_name, $_COOKIE)) {
1320
+ unset($_COOKIE[$cookie_name]);
1321
+ if (!headers_sent()) {
1322
+ $base_domain = $this->getBaseDomain();
1323
+ setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
1324
+ } else {
1325
+ // @codeCoverageIgnoreStart
1326
+ self::errorLog(
1327
+ 'There exists a cookie that we wanted to clear that we couldn\'t '.
1328
+ 'clear because headers was already sent. Make sure to do the first '.
1329
+ 'API call before outputing anything.'
1330
+ );
1331
+ // @codeCoverageIgnoreEnd
1332
+ }
1333
+ }
1334
+ }
1335
+
1336
+ /**
1337
+ * Parses the metadata cookie that our Javascript API set
1338
+ *
1339
+ * @return an array mapping key to value
1340
+ */
1341
+ protected function getMetadataCookie() {
1342
+ $cookie_name = $this->getMetadataCookieName();
1343
+ if (!array_key_exists($cookie_name, $_COOKIE)) {
1344
+ return array();
1345
+ }
1346
+
1347
+ // The cookie value can be wrapped in "-characters so remove them
1348
+ $cookie_value = trim($_COOKIE[$cookie_name], '"');
1349
+
1350
+ if (empty($cookie_value)) {
1351
+ return array();
1352
+ }
1353
+
1354
+ $parts = explode('&', $cookie_value);
1355
+ $metadata = array();
1356
+ foreach ($parts as $part) {
1357
+ $pair = explode('=', $part, 2);
1358
+ if (!empty($pair[0])) {
1359
+ $metadata[urldecode($pair[0])] =
1360
+ (count($pair) > 1) ? urldecode($pair[1]) : '';
1361
+ }
1362
+ }
1363
+
1364
+ return $metadata;
1365
+ }
1366
+
1367
+ protected static function isAllowedDomain($big, $small) {
1368
+ if ($big === $small) {
1369
+ return true;
1370
+ }
1371
+ return self::endsWith($big, '.'.$small);
1372
+ }
1373
+
1374
+ protected static function endsWith($big, $small) {
1375
+ $len = strlen($small);
1376
+ if ($len === 0) {
1377
+ return true;
1378
+ }
1379
+ return substr($big, -$len) === $small;
1380
+ }
1381
+
1382
+ /**
1383
+ * Each of the following four methods should be overridden in
1384
+ * a concrete subclass, as they are in the provided Facebook class.
1385
+ * The Facebook class uses PHP sessions to provide a primitive
1386
+ * persistent store, but another subclass--one that you implement--
1387
+ * might use a database, memcache, or an in-memory cache.
1388
+ *
1389
+ * @see Facebook
1390
+ */
1391
+
1392
+ /**
1393
+ * Stores the given ($key, $value) pair, so that future calls to
1394
+ * getPersistentData($key) return $value. This call may be in another request.
1395
+ *
1396
+ * @param string $key
1397
+ * @param array $value
1398
+ *
1399
+ * @return void
1400
+ */
1401
+ abstract protected function setPersistentData($key, $value);
1402
+
1403
+ /**
1404
+ * Get the data for $key, persisted by BaseFacebook::setPersistentData()
1405
+ *
1406
+ * @param string $key The key of the data to retrieve
1407
+ * @param boolean $default The default value to return if $key is not found
1408
+ *
1409
+ * @return mixed
1410
+ */
1411
+ abstract protected function getPersistentData($key, $default = false);
1412
+
1413
+ /**
1414
+ * Clear the data with $key from the persistent storage
1415
+ *
1416
+ * @param string $key
1417
+ * @return void
1418
+ */
1419
+ abstract protected function clearPersistentData($key);
1420
+
1421
+ /**
1422
+ * Clear all data from the persistent storage
1423
+ *
1424
+ * @return void
1425
+ */
1426
+ abstract protected function clearAllPersistentData();
1427
+ }
trunk/lib/fb/facebook.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2011 Facebook, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once "base_facebook.php";
19
+
20
+ /**
21
+ * Extends the BaseFacebook class with the intent of using
22
+ * PHP sessions to store user ids and access tokens.
23
+ */
24
+ class Facebook extends BaseFacebook
25
+ {
26
+ const FBSS_COOKIE_NAME = 'fbss';
27
+
28
+ // We can set this to a high number because the main session
29
+ // expiration will trump this.
30
+ const FBSS_COOKIE_EXPIRE = 31556926; // 1 year
31
+
32
+ // Stores the shared session ID if one is set.
33
+ protected $sharedSessionID;
34
+
35
+ /**
36
+ * Identical to the parent constructor, except that
37
+ * we start a PHP session to store the user ID and
38
+ * access token if during the course of execution
39
+ * we discover them.
40
+ *
41
+ * @param Array $config the application configuration. Additionally
42
+ * accepts "sharedSession" as a boolean to turn on a secondary
43
+ * cookie for environments with a shared session (that is, your app
44
+ * shares the domain with other apps).
45
+ * @see BaseFacebook::__construct in facebook.php
46
+ */
47
+ public function __construct($config) {
48
+ if (!session_id()) {
49
+ session_start();
50
+ }
51
+ parent::__construct($config);
52
+ if (!empty($config['sharedSession'])) {
53
+ $this->initSharedSession();
54
+ }
55
+ }
56
+
57
+ protected static $kSupportedKeys =
58
+ array('state', 'code', 'access_token', 'user_id');
59
+
60
+ protected function initSharedSession() {
61
+ $cookie_name = $this->getSharedSessionCookieName();
62
+ if (isset($_COOKIE[$cookie_name])) {
63
+ $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
64
+ if ($data && !empty($data['domain']) &&
65
+ self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
66
+ // good case
67
+ $this->sharedSessionID = $data['id'];
68
+ return;
69
+ }
70
+ // ignoring potentially unreachable data
71
+ }
72
+ // evil/corrupt/missing case
73
+ $base_domain = $this->getBaseDomain();
74
+ $this->sharedSessionID = md5(uniqid(mt_rand(), true));
75
+ $cookie_value = $this->makeSignedRequest(
76
+ array(
77
+ 'domain' => $base_domain,
78
+ 'id' => $this->sharedSessionID,
79
+ )
80
+ );
81
+ $_COOKIE[$cookie_name] = $cookie_value;
82
+ if (!headers_sent()) {
83
+ $expire = time() + self::FBSS_COOKIE_EXPIRE;
84
+ setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
85
+ } else {
86
+ // @codeCoverageIgnoreStart
87
+ self::errorLog(
88
+ 'Shared session ID cookie could not be set! You must ensure you '.
89
+ 'create the Facebook instance before headers have been sent. This '.
90
+ 'will cause authentication issues after the first request.'
91
+ );
92
+ // @codeCoverageIgnoreEnd
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Provides the implementations of the inherited abstract
98
+ * methods. The implementation uses PHP sessions to maintain
99
+ * a store for authorization codes, user ids, CSRF states, and
100
+ * access tokens.
101
+ */
102
+ protected function setPersistentData($key, $value) {
103
+ if (!in_array($key, self::$kSupportedKeys)) {
104
+ self::errorLog('Unsupported key passed to setPersistentData.');
105
+ return;
106
+ }
107
+
108
+ $session_var_name = $this->constructSessionVariableName($key);
109
+ $_SESSION[$session_var_name] = $value;
110
+ }
111
+
112
+ protected function getPersistentData($key, $default = false) {
113
+ if (!in_array($key, self::$kSupportedKeys)) {
114
+ self::errorLog('Unsupported key passed to getPersistentData.');
115
+ return $default;
116
+ }
117
+
118
+ $session_var_name = $this->constructSessionVariableName($key);
119
+ return isset($_SESSION[$session_var_name]) ?
120
+ $_SESSION[$session_var_name] : $default;
121
+ }
122
+
123
+ protected function clearPersistentData($key) {
124
+ if (!in_array($key, self::$kSupportedKeys)) {
125
+ self::errorLog('Unsupported key passed to clearPersistentData.');
126
+ return;
127
+ }
128
+
129
+ $session_var_name = $this->constructSessionVariableName($key);
130
+ unset($_SESSION[$session_var_name]);
131
+ }
132
+
133
+ protected function clearAllPersistentData() {
134
+ foreach (self::$kSupportedKeys as $key) {
135
+ $this->clearPersistentData($key);
136
+ }
137
+ if ($this->sharedSessionID) {
138
+ $this->deleteSharedSessionCookie();
139
+ }
140
+ }
141
+
142
+ protected function deleteSharedSessionCookie() {
143
+ $cookie_name = $this->getSharedSessionCookieName();
144
+ unset($_COOKIE[$cookie_name]);
145
+ $base_domain = $this->getBaseDomain();
146
+ setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
147
+ }
148
+
149
+ protected function getSharedSessionCookieName() {
150
+ return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
151
+ }
152
+
153
+ protected function constructSessionVariableName($key) {
154
+ $parts = array('fb', $this->getAppId(), $key);
155
+ if ($this->sharedSessionID) {
156
+ array_unshift($parts, $this->sharedSessionID);
157
+ }
158
+ return implode('_', $parts);
159
+ }
160
+ }
trunk/lib/img/hechoenmexico.png ADDED
Binary file
trunk/lib/img/paypal.png ADDED
Binary file
trunk/lib/img/taco.png ADDED
Binary file
trunk/readme.txt ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP Embed Facebook ===
2
+ Contributors: poxtron
3
+ Donate link: http://www.saliuitl.org/en/wp-embed-facebook
4
+ Tags: facebook, embed, open graph, fbsdk
5
+ Requires at least: 3.0.1
6
+ Tested up to: 3.8.1
7
+ Stable tag: 1.2
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Embed a facebook page, post, event, photo or profile to a post.
12
+
13
+ == Description ==
14
+
15
+ This plugin embeds public the content of a facebook page directly into a wordpress post.
16
+
17
+ **Embeds**
18
+ * posts
19
+ * photos
20
+ * events
21
+ * fan pages
22
+ * community pages
23
+ * profiles
24
+
25
+ **Options** (Settings > Embed Facebook)
26
+ * Change embed width
27
+ * Show like buttons on embedded Facebook pages
28
+
29
+ Customise the look copying the wp-embed-facebook/templates/default content to yourtheme/plugins/wp-embed-fb
30
+
31
+ To use it first you need to create a facebook app and configure for your domain. When you get your App id and App secret copy them to the ¨Embed Facebook¨ page under the Setting section inside wp-admin
32
+
33
+ Put on a single line an url for a facebook page, profile or event, on any of your posts or pages.
34
+
35
+ The information that is shown on your post if from facebook directly, no images or data are stored on your serer. You can not embed data that is not public like ¨invite only¨ events, or private profiles.
36
+
37
+ [Demo](http://saliuitl.org/en/wp-embed-facebook)
38
+
39
+ **On the next version**
40
+ * Templates
41
+
42
+ == Installation ==
43
+
44
+ 1. Download wp embed facebook plugin from [Wordpress](http://wordpress.org/plugins/wp-embed-facebook)
45
+ 1. Create a [facebook app](https://developers.facebook.com/apps) and configure for your domain.
46
+ 1. Copy the app id and app secret to the ¨Embed Facebook¨ page under the Setting section.
47
+ 1. Put a single
48
+ 1. Enjoy !
49
+
50
+ == Changelog ==
51
+
52
+ = 1.2 =
53
+ * Embed posts
54
+ * Embed photos
55
+ * Like buttons
56
+
57
+ = 1.1.1 =
58
+ * Corrected links on events.
59
+
60
+ = 1.1 =
61
+ * Making the plugin public.
62
+
63
+ = 1.0 =
64
+ * Making the plugin.
trunk/templates/default/band.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wpemfb-container" style="min-width:<?php echo $height ?>px">
2
+ <div class="wpemfb-pagebk"
3
+ style=" height:<?php echo $height ?>px;
4
+ width:<?php echo $width?>px;
5
+ background-image: url(<?php echo $fb_data['cover']['source'] ?>);
6
+ background-position: 0% <?php echo $fb_data['cover']['offset_y'] ?>%;
7
+ ">
8
+
9
+ </div>
10
+ <div class="wpemfb-info">
11
+ <div class="wpemfb-pic">
12
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank">
13
+ <img src="http://graph.facebook.com/<?php echo $fb_data['id'] ?>/picture" />
14
+ </a>
15
+ </div>
16
+ <div class="wpemfb-desc">
17
+ <h4 class="wpemfb-title" >
18
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank">
19
+ <?php echo $fb_data['name'] ?>
20
+ </a>
21
+ </h4>
22
+ <?php echo isset($fb_data['genre']) ? $fb_data['genre'].'<br>' : '' ?>
23
+ <?php printf( __( '%d people like this.', 'wp-embed-fb' ), $fb_data['likes'] ); ?><br>
24
+ <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
25
+ </div>
26
+ </div>
27
+ </div>
28
+
29
+
30
+
31
+
{templates/classic → trunk/templates/default}/com-page.php RENAMED
@@ -1,9 +1,3 @@
1
- <?php
2
- /*
3
- * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
- * to access all fb data print_r($fb_data)
5
- */
6
- ?>
7
  <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
8
  <div class="wpemfb-info" style="width: <?php echo $width ?>">
9
  <div class="wpemfb-pic">
@@ -17,7 +11,7 @@
17
  <?php echo $fb_data['name'] ?>
18
  </a>
19
  </h4>
20
- <?php WP_Embed_FB::like_btn($fb_data['id'],$fb_data['likes']) ?><br>
21
  <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
22
  </div>
23
  </div>
 
 
 
 
 
 
1
  <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
2
  <div class="wpemfb-info" style="width: <?php echo $width ?>">
3
  <div class="wpemfb-pic">
11
  <?php echo $fb_data['name'] ?>
12
  </a>
13
  </h4>
14
+ <?php printf( __( '%d people like this.', 'wp-embed-fb' ), $fb_data['likes'] ); ?><br>
15
  <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
16
  </div>
17
  </div>
{templates/classic → trunk/templates/default}/event.php RENAMED
@@ -1,28 +1,38 @@
1
  <?php
2
  /*
3
- * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
- * to access all fb data print_r($fb_data)
 
 
 
 
 
 
 
 
 
 
 
5
  */
6
- ?>
7
- <?php
8
- $start_time_format = !empty($fb_data['is_date_only']) ? '%e %b %Y' : '%e %b %Y %l:%M %P';
9
  $start_time = strtotime($fb_data['start_time']) + get_option('gmt_offset')*3600; //shows event date on local time
10
  ?>
 
11
  <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
12
 
13
  <div class="wpemfb-info">
14
  <div class="wpemfb-pic">
15
- <a href="http://www.facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
16
  <img src="http://graph.facebook.com/<?php echo $fb_data['id'] ?>/picture" />
17
  </a>
18
  </div>
19
  <div class="wpemfb-desc">
20
  <h4 class="wpemfb-title" >
21
- <a href="http://www.facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
22
  <?php echo $fb_data['name'] ?>
23
  </a>
24
  </h4>
25
- <?php echo strftime($start_time_format, $start_time ) ?><br>
26
  <?php
27
  if(isset($fb_data['venue']['id'])){
28
  echo '<a href="http://www.facebook.com/'.$fb_data['venue']['id'].'" target="_blank">'.$fb_data['location'].'</a>';
1
  <?php
2
  /*
3
+ * You can alter this placing a copy on yourtheme/plugins/wp-embed-fb/
4
+ * Event recives the following default info:
5
+ * name
6
+ * id
7
+ * start_time
8
+ * end_time (empty if none)
9
+ * is_date_only (empty if not)
10
+ * description
11
+ * location
12
+ * venue
13
+ * ->id (empty if none)
14
+ * ->name (empty if none)
15
+ * updated_time
16
  */
17
+ $start_time_format = empty($fb_data['is_date_only']) ? __('d M Y','wp-embed-fb') : __('d M Y g:ia','wp-embed-fb');
 
 
18
  $start_time = strtotime($fb_data['start_time']) + get_option('gmt_offset')*3600; //shows event date on local time
19
  ?>
20
+
21
  <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
22
 
23
  <div class="wpemfb-info">
24
  <div class="wpemfb-pic">
25
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
26
  <img src="http://graph.facebook.com/<?php echo $fb_data['id'] ?>/picture" />
27
  </a>
28
  </div>
29
  <div class="wpemfb-desc">
30
  <h4 class="wpemfb-title" >
31
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
32
  <?php echo $fb_data['name'] ?>
33
  </a>
34
  </h4>
35
+ <?php echo date($start_time_format, $start_time ) ?><br>
36
  <?php
37
  if(isset($fb_data['venue']['id'])){
38
  echo '<a href="http://www.facebook.com/'.$fb_data['venue']['id'].'" target="_blank">'.$fb_data['location'].'</a>';
trunk/templates/default/other.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wpemfb-container"
2
+ style=" width:<?php echo $width ?>px;
3
+ margin-left: auto;
4
+ margin-right: auto;
5
+ ">
6
+ <div class="wpemfb-pagebk"
7
+ style=" height:<?php echo $height ?>px;
8
+ width:<?php echo $width?>px;
9
+ background-image: url(<?php echo $fb_data['cover']['source'] ?>);
10
+ background-position: 0% <?php echo $fb_data['cover']['offset_y'] ?>%;
11
+ ">
12
+
13
+ </div>
14
+ <div class="wpemfb-info">
15
+ <div class="wpemfb-pic">
16
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
17
+ <img src="http://graph.facebook.com/<?php echo $fb_data['id'] ?>/picture" />
18
+ </a>
19
+ </div>
20
+ <div class="wpemfb-desc">
21
+ <h4 class="wpemfb-title" >
22
+ <a href="<?php echo $fb_data['link'] ?>" target="_blank" rel="nofollow">
23
+ <?php echo $fb_data['name'] ?>
24
+ </a>
25
+ </h4>
26
+ <?php echo WP_Embed_FB::fb_categories($fb_data['category']) ?><br>
27
+ <?php printf( __( '%d people like this.', 'wp-embed-fb' ), $fb_data['likes'] ); ?><br>
28
+ <?php echo isset($fb_data["website"]) ? WP_Embed_FB::getwebsite($fb_data["website"]) : ""; ?>
29
+ </div>
30
+ </div>
31
+ </div>
trunk/templates/default/photo.php ADDED
@@ -0,0 +1 @@
 
1
+ <pre><?php print_r($fb_data) ?></pre>
{templates/classic → trunk/templates/default}/profile.php RENAMED
@@ -1,9 +1,3 @@
1
- <?php
2
- /*
3
- * You can create your own template by placing a copy of this file on yourtheme/plugins/wp-embed-fb/
4
- * to access all fb data print_r($fb_data)
5
- */
6
- ?>
7
  <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
8
  <div class="wpemfb-info">
9
  <div class="wpemfb-pic">
@@ -14,7 +8,7 @@
14
  <div class="wpemfb-desc">
15
  <h4 class="wpemfb-title" >
16
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
17
- <?php echo $fb_data['name'] ?>
18
  </a>
19
  </h4>
20
  </div>
 
 
 
 
 
 
1
  <div class="wpemfb-container" style="min-width:<?php echo $width ?>px">
2
  <div class="wpemfb-info">
3
  <div class="wpemfb-pic">
8
  <div class="wpemfb-desc">
9
  <h4 class="wpemfb-title" >
10
  <a href="http://facebook.com/<?php echo $fb_data['id'] ?>" target="_blank" rel="nofollow">
11
+ <h3><?php echo $fb_data['name'] ?></h3>
12
  </a>
13
  </h4>
14
  </div>
{templates/classic → trunk/templates/default}/wpemfb.css RENAMED
@@ -1,3 +1,6 @@
 
 
 
1
  .wpemfb-container{
2
  margin-top:5px;
3
  border: 1px solid #23487E;
1
+ .wpemfb-dummy {
2
+ padding-top: 80%;
3
+ }
4
  .wpemfb-container{
5
  margin-top:5px;
6
  border: 1px solid #23487E;
trunk/wp-embed-fb.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package WP_Embed_FB
4
+ * @version 1.0
5
+ */
6
+ /*
7
+ Plugin Name: WP Embed Facebook
8
+ Plugin URI: http://www.saliuitl.org/wp-embed-facebook/
9
+ Description: This plugin transforms facebook links into graphic content.
10
+ Author: Miguel Sirvent
11
+ Version: 1.1
12
+ Author URI: http://www.facebook.com/poxtron
13
+ */
14
+
15
+ add_action('init','wpemfblang');
16
+ function wpemfblang(){
17
+ load_plugin_textdomain( 'wp-embed-fb', '', basename( dirname( __FILE__ ) ) . '/lang' );
18
+ }
19
+
20
+ define('WPEMFBLIB',dirname( __FILE__ ) . '/lib/');
21
+
22
+ require_once WPEMFBLIB.'core.php';
23
+
24
+ register_activation_hook( __FILE__, array('WP_Embed_FB', 'install') );
25
+ //register_uninstall_hook( __FILE__, array('WP_Embed_FB', 'uninstall') );
26
+ register_deactivation_hook( __FILE__, array('WP_Embed_FB', 'uninstall'));
27
+ add_action('init',array('FaceInit','init'));
28
+
29
+ add_action( 'wp_enqueue_scripts', array('WP_Embed_FB', 'wp_enqueue_scripts') );
30
+
31
+ add_filter('the_content', array('WP_Embed_FB','the_content'),10,1);
32
+
33
+ if(is_admin()){
34
+ require_once WPEMFBLIB.'admin.php';
35
+ add_action('admin_menu', array('EmbFbAdmin','add_page'));
36
+ }
37
+
38
+ ?>
wp-embed-fb.php CHANGED
@@ -1,38 +1,38 @@
1
  <?php
2
  /**
3
- * @package WP_Embed_Facebook
4
- * @version 1.3
5
  */
6
  /*
7
  Plugin Name: WP Embed Facebook
8
- Plugin URI: http://www.saliuitl.org/en/wp-embed-facebook/
9
- Description: Embed a Facebook page, post, event, photo or profile to any Wordpress post or page. Copy any fb url to a single line on your post, or use shortcode [facebook url='' width='' temp='']
10
  Author: Miguel Sirvent
11
- Version: 1.3
12
- Author URI: http://www.saliuitl.org/
13
  */
14
 
15
- /*
16
- * Global definitions and core include.
17
- */
18
- define('WPEMFBDIR',dirname(__FILE__));
19
- require_once WPEMFBDIR.'/lib/core.php';
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- /*
22
- * All actions, filters and hooks.
23
- */
24
- register_activation_hook(__FILE__, array('WP_Embed_FB', 'install') );
25
- register_uninstall_hook(__FILE__, array('WP_Embed_FB', 'uninstall') );
26
- add_action('init',array('WP_Embed_FB','init'));
27
- add_action('wp_enqueue_scripts', array('WP_Embed_FB', 'wp_enqueue_scripts') );
28
- add_filter('the_content', array('WP_Embed_FB','fb_scripts'),10,1);
29
- add_filter('the_content', array('WP_Embed_FB','the_content'),10,2);
30
- add_shortcode('facebook', array('WP_Embed_FB','shortcode') );
31
  if(is_admin()){
32
- require_once WPEMFBDIR.'/lib/admin.php';
33
  add_action('admin_menu', array('EmbFbAdmin','add_page'));
34
- add_action('admin_init', array('EmbFbAdmin','admin_init'));
35
-
36
  }
37
 
38
  ?>
1
  <?php
2
  /**
3
+ * @package WP_Embed_FB
4
+ * @version 1.0
5
  */
6
  /*
7
  Plugin Name: WP Embed Facebook
8
+ Plugin URI: http://www.saliuitl.org/wp-embed-facebook/
9
+ Description: This plugin transforms facebook links into graphic content.
10
  Author: Miguel Sirvent
11
+ Version: 1.2.1
12
+ Author URI: http://www.facebook.com/poxtron
13
  */
14
 
15
+ add_action('init','wpemfblang');
16
+ function wpemfblang(){
17
+ load_plugin_textdomain( 'wp-embed-fb', '', basename( dirname( __FILE__ ) ) . '/lang' );
18
+ }
19
+
20
+ define('WPEMFBLIB',dirname( __FILE__ ) . '/lib/');
21
+
22
+ require_once WPEMFBLIB.'core.php';
23
+
24
+ register_activation_hook( __FILE__, array('WP_Embed_FB', 'install') );
25
+ //register_uninstall_hook( __FILE__, array('WP_Embed_FB', 'uninstall') );
26
+ register_deactivation_hook( __FILE__, array('WP_Embed_FB', 'uninstall'));
27
+ add_action('init',array('FaceInit','init'));
28
+
29
+ add_action( 'wp_enqueue_scripts', array('WP_Embed_FB', 'wp_enqueue_scripts') );
30
+
31
+ add_filter('the_content', array('WP_Embed_FB','the_content'),10,1);
32
 
 
 
 
 
 
 
 
 
 
 
33
  if(is_admin()){
34
+ require_once WPEMFBLIB.'admin.php';
35
  add_action('admin_menu', array('EmbFbAdmin','add_page'));
 
 
36
  }
37
 
38
  ?>