1 | <?php
|
---|
2 | /*
|
---|
3 | Plugin Name: Facebook Connector
|
---|
4 | Plugin URI: http://www.sociable.es/facebook-connect
|
---|
5 | Description: Allows the use of Facebook Connect for account registration, authentication, and commenting.
|
---|
6 | Author: Javier Reyes
|
---|
7 | Author URI: http://www.sociable.es/
|
---|
8 | Version: 1.2.1
|
---|
9 | License: GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html)
|
---|
10 | */
|
---|
11 |
|
---|
12 | define ( 'FBCONNECT_PLUGIN_REVISION', preg_replace( '/\$Rev: (.+) \$/', 'svn-\\1',
|
---|
13 | '$Rev: 62 $') );
|
---|
14 |
|
---|
15 | define ( 'FBCONNECT_DB_REVISION', 5);
|
---|
16 |
|
---|
17 |
|
---|
18 | define ( 'FBCONNECT_LOG_LEVEL', 'warning');
|
---|
19 |
|
---|
20 | set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
|
---|
21 |
|
---|
22 | require_once('fbConnectLogic.php');
|
---|
23 | require_once('fbConnectInterface.php');
|
---|
24 |
|
---|
25 |
|
---|
26 | restore_include_path();
|
---|
27 |
|
---|
28 | @session_start();
|
---|
29 |
|
---|
30 | if (! defined('WP_CONTENT_DIR'))
|
---|
31 | define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
|
---|
32 |
|
---|
33 | if (! defined('WP_CONTENT_URL'))
|
---|
34 | define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
|
---|
35 |
|
---|
36 | if (! defined('WP_PLUGIN_DIR'))
|
---|
37 | define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
|
---|
38 |
|
---|
39 | if (! defined('WP_PLUGIN_URL'))
|
---|
40 | define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins');
|
---|
41 |
|
---|
42 | if (isset($_REQUEST["fb_facebookapp_mode"])){
|
---|
43 | $_SESSION["fb_facebookapp_mode"]= $_REQUEST["fb_facebookapp_mode"];
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | if ((isset($_SESSION["fb_facebookapp_mode"]) && $_SESSION["fb_facebookapp_mode"]=="on") || isset($_REQUEST["fb_sig_user"]) || isset($_REQUEST["fb_sig_in_profile_tab"])){
|
---|
48 | define ('FBCONNECT_CANVAS', true);
|
---|
49 | }else{
|
---|
50 | define ('FBCONNECT_CANVAS', false);
|
---|
51 | }
|
---|
52 |
|
---|
53 | define ('FBCONNECT_PLUGIN_BASENAME', plugin_basename(dirname(__FILE__)));
|
---|
54 | define ('FBCONNECT_PLUGIN_PATH', WP_PLUGIN_DIR."/".FBCONNECT_PLUGIN_BASENAME);
|
---|
55 | define ('FBCONNECT_PLUGIN_URL', WP_PLUGIN_URL."/".FBCONNECT_PLUGIN_BASENAME);
|
---|
56 | define ('FBCONNECT_PLUGIN_LANG', FBCONNECT_PLUGIN_BASENAME."/lang");
|
---|
57 |
|
---|
58 | //wp_enqueue_script('jquery');
|
---|
59 |
|
---|
60 | if (!class_exists('WPfbConnect')):
|
---|
61 | class WPfbConnect {
|
---|
62 | var $store;
|
---|
63 | var $consumer;
|
---|
64 |
|
---|
65 | var $log;
|
---|
66 | var $status = array();
|
---|
67 |
|
---|
68 | var $message; // Message to be displayed to the user.
|
---|
69 | var $action; // Internal action tag. 'success', 'warning', 'error', 'redirect'.
|
---|
70 |
|
---|
71 | var $response;
|
---|
72 |
|
---|
73 | var $enabled = true;
|
---|
74 |
|
---|
75 | var $bind_done = false;
|
---|
76 |
|
---|
77 |
|
---|
78 | function WPfbConnect() {
|
---|
79 | $this->log = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'FBCONNECT');
|
---|
80 |
|
---|
81 | // Set the log level
|
---|
82 | $fbconnect_log_level = constant('PEAR_LOG_' . strtoupper(FBCONNECT_LOG_LEVEL));
|
---|
83 | $this->log->setMask(Log::UPTO($fbconnect_log_level));
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Set Status.
|
---|
89 | **/
|
---|
90 | function setStatus($slug, $state, $message) {
|
---|
91 | $this->status[$slug] = array('state'=>$state,'message'=>$message);
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | function textdomain() {
|
---|
96 | load_plugin_textdomain('fbconnect', PLUGINDIR ."/".FBCONNECT_PLUGIN_LANG);
|
---|
97 | }
|
---|
98 |
|
---|
99 | function table_prefix() {
|
---|
100 | global $wpdb;
|
---|
101 | return isset($wpdb->base_prefix) ? $wpdb->base_prefix : $wpdb->prefix;
|
---|
102 | }
|
---|
103 |
|
---|
104 | function comments_table_name() { return WPfbConnect::table_prefix() . 'comments'; }
|
---|
105 | function usermeta_table_name() { return WPfbConnect::table_prefix() . 'usermeta'; }
|
---|
106 | function users_table_name() { return WPfbConnect::table_prefix() . 'users'; }
|
---|
107 | }
|
---|
108 | endif;
|
---|
109 |
|
---|
110 | if (!function_exists('fbconnect_init')):
|
---|
111 | function fbconnect_init() {
|
---|
112 | if ($GLOBALS['fbconnect'] && is_a($GLOBALS['fbconnect'], 'WPfbConnect')) {
|
---|
113 | return;
|
---|
114 | }
|
---|
115 |
|
---|
116 | $GLOBALS['fbconnect'] = new WPfbConnect();
|
---|
117 | }
|
---|
118 | endif;
|
---|
119 |
|
---|
120 | if (!function_exists('fbconnect_title')):
|
---|
121 | function fbconnect_title($title) {
|
---|
122 | if($_REQUEST['fbconnect_action']=="community"){
|
---|
123 | return __('Community', 'fbconnect')." - ".$title;
|
---|
124 | }else if($_REQUEST['fbconnect_action']=="myhome"){
|
---|
125 | $userprofile = WPfbConnect_Logic::get_user();
|
---|
126 | return $userprofile->display_name." - ".$title;
|
---|
127 | }else if($_REQUEST['fbconnect_action']=="invite"){
|
---|
128 | return _e('Invite your friends', 'fbconnect')." - ".$title;
|
---|
129 | }
|
---|
130 |
|
---|
131 | return $title;
|
---|
132 | }
|
---|
133 | endif;
|
---|
134 |
|
---|
135 | /*
|
---|
136 | Ver rewrite.php
|
---|
137 | if (!function_exists('fbconnect_add_custom_urls')):
|
---|
138 | function fbconnect_add_custom_urls() {
|
---|
139 | add_rewrite_rule('(userprofile)/[/]?([0-9]*)[/]?([0-9]*)$',
|
---|
140 | 'index.php?fbconnect_action=myhome&fbuserid=$matches[2]&var2=$matches[3]');
|
---|
141 | add_rewrite_tag('%fbuserid%', '[0-9]+');
|
---|
142 | add_rewrite_tag('%var2%', '[0-9]+');
|
---|
143 | }
|
---|
144 | endif;
|
---|
145 | */
|
---|
146 | //wp_enqueue_script( 'prototype' );
|
---|
147 | // -- Register actions and filters -- //
|
---|
148 |
|
---|
149 | add_filter('wp_title', 'fbconnect_title');
|
---|
150 |
|
---|
151 | // runs the function in the init hook
|
---|
152 | //add_action('init', 'fbconnect_add_custom_urls');
|
---|
153 |
|
---|
154 | add_filter('get_comment_author_url', array('WPfbConnect_Logic', 'get_comment_author_url'));
|
---|
155 |
|
---|
156 |
|
---|
157 | if( get_option('fb_add_post_share') ) {
|
---|
158 | add_action('the_content', array( 'WPfbConnect_Interface', 'add_fbshare' ) );
|
---|
159 | }
|
---|
160 |
|
---|
161 | add_action( 'init', array( 'WPfbConnect','textdomain') ,1 ); // load textdomain
|
---|
162 |
|
---|
163 | register_activation_hook(FBCONNECT_PLUGIN_BASENAME.'/fbConnectCore.php', array('WPfbConnect_Logic', 'activate_plugin'));
|
---|
164 | register_deactivation_hook(FBCONNECT_PLUGIN_BASENAME.'/fbConnectCore.php', array('WPfbConnect_Logic', 'deactivate_plugin'));
|
---|
165 |
|
---|
166 | add_action( 'admin_menu', array( 'WPfbConnect_Interface', 'add_admin_panels' ) );
|
---|
167 |
|
---|
168 | add_filter('language_attributes', array('WPfbConnect_Logic', 'html_namespace'));
|
---|
169 | add_filter('get_avatar', array('WPfbConnect_Logic', 'fb_get_avatar'),10,4);
|
---|
170 | // Add hooks to handle actions in WordPress
|
---|
171 |
|
---|
172 | //add_action( 'wp_authenticate', array( 'WPfbConnect_Logic', 'wp_authenticate' ) ); // fbconnect loop start
|
---|
173 | add_action( 'wp_logout', array( 'WPfbConnect_Logic', 'fb_logout'),1);
|
---|
174 |
|
---|
175 | add_action( 'init', array( 'WPfbConnect_Logic', 'wp_login_fbconnect' ),100 ); // fbconnect loop done
|
---|
176 |
|
---|
177 |
|
---|
178 | // Comment filtering
|
---|
179 | add_action( 'comment_post', array( 'WPfbConnect_Logic', 'comment_fbconnect' ), 5 );
|
---|
180 |
|
---|
181 | //add_filter( 'comment_post_redirect', array( 'WPfbConnect_Logic', 'comment_post_redirect'), 0, 2);
|
---|
182 | if( get_option('fb_enable_approval') ) {
|
---|
183 | add_filter( 'pre_comment_approved', array('WPfbConnect_Logic', 'comment_approval'));
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | // include internal stylesheet
|
---|
188 | add_action( 'wp_head', array( 'WPfbConnect_Interface', 'style'));
|
---|
189 | add_action( 'login_head', array( 'WPfbConnect_Interface', 'style'));
|
---|
190 |
|
---|
191 | if( get_option('fb_enable_commentform') ) {
|
---|
192 | add_action( 'comment_form', array( 'WPfbConnect_Interface', 'comment_form'), 10);
|
---|
193 | }
|
---|
194 |
|
---|
195 | add_action( 'wp_footer', array( 'WPfbConnect_Logic', 'fbconnect_init_scripts'), 1);
|
---|
196 |
|
---|
197 | if(!function_exists('carga_template')):
|
---|
198 | function carga_template() {
|
---|
199 | if (isset($_REQUEST['fbconnect_action'])){
|
---|
200 | set_include_path( TEMPLATEPATH . PATH_SEPARATOR . dirname(__FILE__) .PATH_SEPARATOR. WP_PLUGIN_DIR.'/'.FBCONNECT_PLUGIN_BASENAME. PATH_SEPARATOR . get_include_path() );
|
---|
201 | if($_REQUEST['fbconnect_action']=="community"){
|
---|
202 | include( 'community.php');
|
---|
203 | }else if($_REQUEST['fbconnect_action']=="myhome"){
|
---|
204 | include( 'myhome.php');
|
---|
205 | }else if($_REQUEST['fbconnect_action']=="tab"){
|
---|
206 | include('fbconnect_tab.php');
|
---|
207 | }else if($_REQUEST['fbconnect_action']=="invite"){
|
---|
208 | include('invitefriends.php');
|
---|
209 | }else if($_REQUEST['fbconnect_action']=="logout"){
|
---|
210 | if(function_exists('wp_logout')):
|
---|
211 | wp_logout();
|
---|
212 | endif;
|
---|
213 | if(function_exists('wp_redirect')):
|
---|
214 | wp_redirect( get_option('siteurl') );
|
---|
215 | endif;
|
---|
216 | }else if($_REQUEST['fbconnect_action']=="fbfeed"){
|
---|
217 | include( 'fbfeed.php');
|
---|
218 | }
|
---|
219 | restore_include_path();
|
---|
220 | exit;
|
---|
221 | }
|
---|
222 | }
|
---|
223 | endif;
|
---|
224 | add_action('template_redirect', 'carga_template');
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * If the current comment was submitted with FacebookConnect, return true
|
---|
228 | * useful for <?php echo ( is_comment_fbconnect() ? 'Submitted with FacebookConnect' : '' ); ?>
|
---|
229 | */
|
---|
230 | if(!function_exists('is_comment_fbconnect')):
|
---|
231 | function is_comment_fbconnect() {
|
---|
232 | global $comment;
|
---|
233 | return ( $comment->fbconnect == 1 );
|
---|
234 | }
|
---|
235 | endif;
|
---|
236 |
|
---|
237 | /**
|
---|
238 | * If the current user registered with FacebookConnect, return true
|
---|
239 | */
|
---|
240 | if(!function_exists('is_user_fbconnect')):
|
---|
241 | function is_user_fbconnect($id = null) {
|
---|
242 | global $current_user;
|
---|
243 | $user = $current_user;
|
---|
244 | if ($id != null) {
|
---|
245 | $user = get_userdata($id);
|
---|
246 | }
|
---|
247 | if($user!=null && $user->fbconnect_userid){
|
---|
248 | return true;
|
---|
249 | }else{
|
---|
250 | return false;
|
---|
251 | }
|
---|
252 | }
|
---|
253 | endif;
|
---|
254 |
|
---|
255 |
|
---|
256 | //MAIN WIDGET
|
---|
257 | if(!function_exists('widget_FacebookConnector_init')):
|
---|
258 | function widget_FacebookConnector_init() {
|
---|
259 | if (!function_exists('register_sidebar_widget')) return;
|
---|
260 | function widget_FacebookConnector($args) {
|
---|
261 |
|
---|
262 | extract($args);
|
---|
263 |
|
---|
264 | $options = get_option('widget_FacebookConnector');
|
---|
265 |
|
---|
266 | if (!isset($options) || $options==""){
|
---|
267 | $before_title ="<h2>";
|
---|
268 | $after_title ="</h2>";
|
---|
269 | $options = widget_FacebookConnector_init_options($options);
|
---|
270 | }
|
---|
271 | $title = $options['title'];
|
---|
272 | $welcometext = $options['welcometext'];
|
---|
273 | $footertext = $options['footertext'];
|
---|
274 | $invitetext = $options['invitetext'];
|
---|
275 | $lastvisittext = $options['lastvisittext'];
|
---|
276 | $logintext = $options['logintext'];
|
---|
277 | $loginbutton = $options['loginbutton'];
|
---|
278 | $alreadytext = $options['alreadytext'];
|
---|
279 | $maxlastusers = $options['maxlastusers'];
|
---|
280 |
|
---|
281 | echo $before_widget . $before_title . $title . $after_title;
|
---|
282 |
|
---|
283 | $fb_user = fb_get_loggedin_user();
|
---|
284 |
|
---|
285 | $user = wp_get_current_user();
|
---|
286 |
|
---|
287 | $users = WPfbConnect_Logic::get_lastusers_fbconnect($maxlastusers);
|
---|
288 | $siteurl = get_option('siteurl');
|
---|
289 |
|
---|
290 | $uri = "";
|
---|
291 | if (isset($_SERVER["REQUEST_URI"])){
|
---|
292 | $uri = $_SERVER["REQUEST_URI"];
|
---|
293 | }
|
---|
294 |
|
---|
295 | set_include_path( TEMPLATEPATH . PATH_SEPARATOR . dirname(__FILE__) .PATH_SEPARATOR. WP_PLUGIN_DIR.'/'.FBCONNECT_PLUGIN_BASENAME. PATH_SEPARATOR . get_include_path() );
|
---|
296 |
|
---|
297 | include( 'fbconnect_widget.php');
|
---|
298 |
|
---|
299 | restore_include_path();
|
---|
300 |
|
---|
301 | echo $footertext . $after_widget;
|
---|
302 | }
|
---|
303 |
|
---|
304 | function widget_FacebookConnector_init_options($options){
|
---|
305 | if (!isset($options['title'])){
|
---|
306 | $options['title'] = "Community";
|
---|
307 | }
|
---|
308 | if (!isset($options['welcometext'])){
|
---|
309 | $options['welcometext'] = "Welcome to ".get_option('blogname')."!";
|
---|
310 | }
|
---|
311 | if (!isset($options['lastvisittext'])){
|
---|
312 | $options['lastvisittext'] = "Last visitors";
|
---|
313 | }
|
---|
314 | if (!isset($options['invitetext'])){
|
---|
315 | $options['invitetext'] = "Invite your friends!";
|
---|
316 | }
|
---|
317 | if (!isset($options['logintext'])){
|
---|
318 | $options['logintext'] = "Login using Facebook:";
|
---|
319 | }
|
---|
320 | if (!isset($options['loginbutton'])){
|
---|
321 | $options['loginbutton'] = "long";
|
---|
322 | }
|
---|
323 | if (!isset($options['alreadytext'])){
|
---|
324 | $options['alreadytext'] = "Already a member?";
|
---|
325 | }
|
---|
326 | if (!isset($options['footertext'])){
|
---|
327 | $options['footertext'] = 'Powered by <a href="http://www.sociable.es">Sociable!</a>';
|
---|
328 | }
|
---|
329 | if (!isset($options['maxlastusers'])){
|
---|
330 | $options['maxlastusers'] = "9";
|
---|
331 | }
|
---|
332 | return $options;
|
---|
333 | }
|
---|
334 |
|
---|
335 | function widget_FacebookConnector_control() {
|
---|
336 | $options = get_option('widget_FacebookConnector');
|
---|
337 | if ( $_POST['FacebookConnector-submit'] ) {
|
---|
338 | $options['title'] = strip_tags(stripslashes($_POST['FacebookConnector-title']));
|
---|
339 | $options['welcometext'] = stripslashes($_POST['FacebookConnector-welcometext']);
|
---|
340 | $options['footertext'] = stripslashes($_POST['FacebookConnector-footertext']);
|
---|
341 | $options['invitetext'] = stripslashes($_POST['FacebookConnector-invitetext']);
|
---|
342 | $options['lastvisittext'] = stripslashes($_POST['FacebookConnector-lastvisittext']);
|
---|
343 | $options['logintext'] = stripslashes($_POST['FacebookConnector-logintext']);
|
---|
344 | $options['loginbutton'] = stripslashes($_POST['FacebookConnector-loginbutton']);
|
---|
345 | $options['alreadytext'] = stripslashes($_POST['FacebookConnector-alreadytext']);
|
---|
346 | $options['maxlastusers'] = (int)$_POST['FacebookConnector-maxlastusers'];
|
---|
347 | update_option('widget_FacebookConnector', $options);
|
---|
348 | }
|
---|
349 |
|
---|
350 | $options = widget_FacebookConnector_init_options($options);
|
---|
351 |
|
---|
352 | $title = htmlspecialchars($options['title'], ENT_QUOTES);
|
---|
353 | $welcometext = htmlspecialchars($options['welcometext'], ENT_QUOTES);
|
---|
354 | $footertext = htmlspecialchars($options['footertext'], ENT_QUOTES);
|
---|
355 | $invitetext = htmlspecialchars($options['invitetext'], ENT_QUOTES);
|
---|
356 | $lastvisittext = htmlspecialchars($options['lastvisittext'], ENT_QUOTES);
|
---|
357 | $logintext = htmlspecialchars($options['logintext'], ENT_QUOTES);
|
---|
358 | $loginbutton = htmlspecialchars($options['loginbutton'], ENT_QUOTES);
|
---|
359 | $alreadytext = htmlspecialchars($options['alreadytext'], ENT_QUOTES);
|
---|
360 | $maxlastusers = htmlspecialchars($options['maxlastusers'], ENT_QUOTES);
|
---|
361 | //get_option('blogname')
|
---|
362 |
|
---|
363 | echo '<p style="text-align:right;"><label for="FacebookConnector-title">'.__('Title:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-title" name="FacebookConnector-title" type="text" value="'.$title.'" /></label></p>';
|
---|
364 | echo '<p style="text-align:right;"><label for="FacebookConnector-welcometext">'.__('Welcome msg:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-welcometext" name="FacebookConnector-welcometext" type="text" value="'.$welcometext.'" /></label></p>';
|
---|
365 | echo '<p style="text-align:right;"><label for="FacebookConnector-footertext">'.__('Footer msg:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-footertext" name="FacebookConnector-footertext" type="text" value="'.$footertext.'" /></label></p>';
|
---|
366 | echo '<p style="text-align:right;"><label for="FacebookConnector-invitetext">'.__('Invite msg:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-invitetext" name="FacebookConnector-invitetext" type="text" value="'.$invitetext.'" /></label></p>';
|
---|
367 | echo '<p style="text-align:right;"><label for="FacebookConnector-lastvisittext">'.__('Visitors title:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-lastvisittext" name="FacebookConnector-lastvisittext" type="text" value="'.$lastvisittext.'" /></label></p>';
|
---|
368 | echo '<p style="text-align:right;"><label for="FacebookConnector-logintext">'.__('Login msg:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-logintext" name="FacebookConnector-logintext" type="text" value="'.$logintext.'" /></label></p>';
|
---|
369 | echo '<p style="text-align:right;"><label for="FacebookConnector-alreadytext">'.__('Member msg:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-alreadytext" name="FacebookConnector-alreadytext" type="text" value="'.$alreadytext.'" /></label></p>';
|
---|
370 | echo '<p style="text-align:right;"><label for="FacebookConnector-maxlastusers">'.__('Max users:', 'fbconnect').' <input style="width: 180px;" id="FacebookConnector-maxlastusers" name="FacebookConnector-maxlastusers" type="text" value="'.$maxlastusers.'" /></label></p>';
|
---|
371 | echo '<p style="text-align:right;"><label for="FacebookConnector-loginbutton">'.__('Login button:', 'fbconnect').' <SELECT style="width: 180px;" id="FacebookConnector-loginbutton" name="FacebookConnector-loginbutton">';
|
---|
372 | echo '<OPTION ';
|
---|
373 | if ($loginbutton=="long") echo "SELECTED";
|
---|
374 | echo ' VALUE="long">long</OPTION>';
|
---|
375 | echo ' <OPTION ';
|
---|
376 | if ($loginbutton=="short") echo "SELECTED";
|
---|
377 | echo ' VALUE="short">short</OPTION>';
|
---|
378 | echo '</SELECT></label></p>';
|
---|
379 | echo '<input type="hidden" id="FacebookConnector-submit" name="FacebookConnector-submit" value="1" />';
|
---|
380 | }
|
---|
381 |
|
---|
382 | register_sidebar_widget('FacebookConnector', 'widget_FacebookConnector');
|
---|
383 | register_widget_control('FacebookConnector', 'widget_FacebookConnector_control', 300, 100);
|
---|
384 | }
|
---|
385 | endif;
|
---|
386 |
|
---|
387 | add_action('plugins_loaded', 'widget_FacebookConnector_init');
|
---|
388 |
|
---|
389 | ?>
|
---|