Facebook API Key for use. Version: 1.0 */ require_once('common.php'); require_once('config.php'); define('FBC_APP_KEY_OPTION', 'fbc_app_key_option'); define('FBC_APP_SECRET_OPTION', 'fbc_app_secret_option'); define('FBC_APP_EXTENSIONS_OPTION', 'fbc_app_extensions_option'); define('FBC_LAST_UPDATED_CACHE_OPTION', 'fbc_last_updated_cache_option'); define('FBC_REMOVE_NOFOLLOW_OPTION', 'fbc_remove_nofollow_option'); function fbc_get_fbconnect_user() { return fbc_facebook_client()->get_loggedin_user(); } function fbc_login_header($login_state, $fbuid, $wpuid) { if (FBC_DEBUG_LOGIN_HEADER) { header("X-FBC-Login: $login_state fbuid=$fbuid, wpuid=$wpuid"); } } function fbc_init_auth() { $fbuid = fbc_facebook_client()->get_loggedin_user(); $user = wp_get_current_user(); $assoc_fbuid = fbc_get_fbuid($user->ID); if ($assoc_fbuid) { if ($fbuid == $assoc_fbuid) { // user is already logged in to both fbc_login_header('logged in', $fbuid, $user->ID); return; } else { //wp session, no fbsession = logout of wp and reload page // or, user is logged in under a different fb account wp_logout(); header('Location: ' . $_SERVER['REQUEST_URI']); fbc_login_header('logging user out assoc='. $assoc_fbuid, $fbuid, $user->ID); exit(); } } else { if ($user->ID) { fbc_login_header('non-facebook user', $fbuid, $user->ID); // wpuser not associated w/ fb. do nothing return; } else if($fbuid) { // not a wp user, but fb authed = log them in to wp $res = fbc_login_if_necessary(); if ($res > 0) { $wp_uid = fbc_fbuser_to_wpuser($res); wp_set_current_user($wp_uid); fbc_login_header('login sucessful', $fbuid, $wp_uid); } else { fbc_login_header('login error ' . $res, $fbuid, $user->ID); } } else { fbc_login_header('anonymous', 0, 0); // neither facebook nor wordpress, do nothing return; } } } function fbc_init() { if (fbc_is_configured()) { add_action('init', 'fbc_init_auth'); /* Includes any necessary js in the page, registers onload handlers, and prints the absolutely positioned "Welcome, username" div. */ add_action('wp_footer', 'fbc_footer'); /* Adds a "Connect" button to the login form, and handles fbconnect logout when a wordpress logout is performed. */ add_action('login_form', 'fbc_login_form'); /* Prints fbml with the user's profile pic when that user is a facebook connect user. */ add_filter('get_avatar', 'fbc_get_avatar', 10, 4); /* Make sure the comment author info is in sync with the db. */ add_filter('get_comment_author', 'fbc_get_comment_author'); add_filter('get_comment_author_url', 'fbc_get_comment_author_url'); /* Rahul- Add filter to content */ add_filter( 'the_content', 'show_file_after_fblogin' ); // Rahul - This action fire when publish post or page //Rahul - This is for updating facebook users wall - Rahul add_action( 'add_meta_boxes', 'myplugin_add_custom_box' ); add_action( 'save_post', 'myplugin_save_postdata' ); add_action('save_post', 'fb_post_friends'); /* Remove nofollow from links back to profile pages */ if (get_option(FBC_REMOVE_NOFOLLOW_OPTION) === 'true') { add_filter('get_comment_author_link', 'fbc_remove_nofollow'); } /* Add the xmlns:fb namespace to the page. This is necessary to be stricty correct with xhtml, and more importantly it's necessary for xfbml to work in IE. */ add_filter('language_attributes', 'fbc_language_attributes'); add_action('wp_head', 'fbc_og_head'); /* Setup feedforms and post-specific data. */ add_action('comment_form', 'fbc_comment_form_setup'); /* Why do this? So you can print the form with do_action('fbc_comment_form') and not spew errors if the plugin is removed. */ add_action('fbc_display_login_state', 'fbc_display_login_state'); add_action('fbc_display_login_button', 'fbc_display_login_button'); } /* Install the admin menu. */ add_action('admin_menu', 'fbc_add_options_to_admin'); } /* Adds a box to the main column on the Post and Page edit screens */ function myplugin_add_custom_box() { add_meta_box( 'myplugin_sectionid', __( 'Post on facebook user\'s wall', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post' ); add_meta_box( 'myplugin_sectionid', __( 'Post on facebook user\'s wall', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'page' ); } /* Prints the box content */ function myplugin_inner_custom_box( $post ) { // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' ); // The actual fields for data entry echo ' '; echo ' '; } /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) return; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return; } // OK, we're authenticated: we need to find and save the data $mydata = $_POST['myplugin_new_field']; // Do something with $mydata // probably using add_post_meta(), update_post_meta(), or // a custom table (see Further Reading section below) } function fb_post_friends() { if(isset($_POST['myplugin_new_field'])) { $app_key = get_option(FBC_APP_KEY_OPTION); $app_secret = get_option(FBC_APP_SECRET_OPTION); $extensions = get_option(FBC_APP_EXTENSIONS_OPTION); global $post; $content = substr(strip_tags($post->post_content),0,300).'....'; $tit = $post->post_title; $hreflink = $post->guid; $name = get_bloginfo('name'); $szPostContent = $post->post_content; $szSearchPattern = '/(? 0 ) { // Now here you would do whatever you need to do with the images // For this example the images are just displayed for ( $i=0; $i < $iNumberOfPics ; $i++ ) { $img1 = substr($aPics[0][$i],0,-1); $myimg[] = substr($img1,5,strlen($img1)); } } else { $myimg[0] = plugins_url() . '/wp-facebookconnect/images/applogo.png'; } // Set all attributes require for the post $attachment = array ( 'message' => $tit, 'picture' => $myimg[0], 'link' => $hreflink, 'name' => $tit, 'caption' => $name, 'description' => $content); // create facebook SDk object $rrd = new Rahulfacebook(array( 'appId' => $app_key, 'secret' => $app_secret, )); $access_token = $rrd->getAccessToken(); global $wpdb; $wp_user_search = $wpdb->get_results("SELECT ID, display_name,user_login FROM $wpdb->users ORDER BY ID"); //check for wordpress user and if have permission for posr to wall. //It will post on user's wall and delete user's who are unsubscribe application from facebook account $cnt = 0; foreach ( $wp_user_search as $userid ) { $user_id = (int) $userid->ID; $user_info = get_userdata($user_id); if(substr($user_info->user_login,0,2) == 'fb') { $arr[$cnt] = str_replace('fb','',$user_info->user_login); if($access_token) { $permissions = $rrd->api( "/".$arr[$cnt]."/permissions" ); $perdata = count($permissions['data']); if($perdata > 0) { $appcnt = count($permissions['data']); if( array_key_exists('publish_stream', $permissions['data'][0]) && $appcnt > 0 ) { $rrd->api('/'.$arr[$cnt].'/feed', 'post', $attachment); } else { //wp_delete_user($user_id); $user = new WP_User($user_id); $user->set_role(''); } } else { //wp_delete_user($user_id); $user = new WP_User($user_id); $user->set_role(''); } $cnt++; } } } } } function show_file_after_fblogin($content) { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } //filter file content and find the extension specified in admin setting $posttext = $content; $document = DOMDocument::loadHTML($posttext); $xpath = new DOMXPath($document); $hrefs = $xpath->query('//a/@href'); $count = $hrefs->length; $myarray = array(); $cnt = 0; foreach($hrefs as $href) { $info = pathinfo($href->nodeValue); $extensions = get_option(FBC_APP_EXTENSIONS_OPTION); $uprext = strtoupper($extensions); $lwrext = strtolower($extensions); $expuprext = explode(',',$uprext); $explwrext = explode(',',$lwrext); if(in_array($info['extension'],$expuprext) || in_array($info['extension'],$explwrext) ) { $myarray[$cnt] = $href->nodeValue; $cnt++; } } $cnten = htmlspecialchars($content); $tot = count($myarray); if($tot <= 0) { echo $content; } elseif($tot > 0 && is_user_logged_in()) { echo $cont = fbc_render_login_state(); echo $content; } elseif($tot > 0 && !is_user_logged_in()) { if($tot > 0 && !is_user_logged_in()) { for($i=0;$i<$tot;$i++) { $myarray[$i]; $cnten = str_replace($myarray[$i],"javascript:alert('Please login to Facebook to download File')",$cnten); } $cnten = str_replace('_blank','_self',$cnten); $b = html_entity_decode($cnten); //echo $b = preg_replace('/(<]*)>/i', '$1 style="color:red;">', $b); //echo $cnten = html_entity_decode($cnten); $dir = plugins_url() . '/amr-fbdownload/images/fb_nouser.jpg'; $dir1 = plugins_url() . '/amr-fbdownload/images/facebook_login.jpg'; $result = '
Facebook Welcome to GujaratiGupShup
Login via    to download the file!

By logging in you agree to subscribe to our montly newsletter.
'; echo $result.$b; } } } function fbc_add_options_to_admin() { if (function_exists('add_options_page')) { add_options_page('Amar FB Download', 'Amar FB Download', 8, __FILE__, 'fbc_admin_options'); } } function fbc_remove_nofollow($anchor) { global $comment; // Only remove for facebook comments, since url is trusted if ($comment->user_id && fbc_get_fbuid($comment->user_id)) { return preg_replace('/ rel=[\"\'](.*)nofollow(.*?)[\"\']/', ' rel="$1 $2" ', $anchor); } return $anchor; } function fbc_is_app_config_valid($api_key, $secret, &$error) { $facebook = new Facebook($api_key, $secret, false, 'connect.facebook.com'); $api_client = $facebook->api_client; // The following line causes an error in the PHP admin console if // you are using php4. try { // ATTENTION: This plugin is not compatible with PHP4 $api_client->admin_getAppProperties(array('application_name')); $success = true; } catch(Exception $e) { $success = false; $error = $e->getMessage(); } return $success; } function fbc_get_comment_author_url($url) { global $comment; if ($comment->user_id) { $user = get_userdata($comment->user_id); if ($user) { return $user->user_url; } else { return null; } } else { return $url; } } function fbc_get_comment_author($author) { global $comment; // normally wordpress will not update the name of logged in comment // authors if they change it after the fact. This hook makes sure // we use the most recent name when displaying comments. if ($comment->user_id) { $user = get_userdata($comment->user_id); if ($user) { if ($fbuid = fbc_get_fbuid($comment->user_id)) { // Wrap in fb:name. This helps if the name wasn't populated // correctly on initial login return '' . fbc_txt2html($user->display_name) . ''; } else { return fbc_txt2html($user->display_name); } } else { // This probably means the account was deleted. // Should it says something like "Unknown user" or "deleted account"? return _(FBC_ANONYMOUS_DISPLAYNAME); } } else { return $author; } } function fbc_clear_config() { update_option(FBC_APP_KEY_OPTION, null); update_option(FBC_APP_SECRET_OPTION, null); update_option(FBC_APP_EXTENSIONS_OPTION, null); } function fbc_is_configured() { $app_key = get_option(FBC_APP_KEY_OPTION); $app_secret = get_option(FBC_APP_SECRET_OPTION); $extensions = get_option(FBC_APP_EXTENSIONS_OPTION); return !empty($app_key) && !empty($app_secret); } function fbc_language_attributes($output) { return $output . ' xmlns:fb="http://www.facebook.com/2008/fbml" '. ' xmlns:og="http://opengraphprotocol.org/schema/" '; } function fbc_og_head() { if (!is_singular()) { return ; } $title = ltrim(wp_title($sep='',$display=false,$seplocation='')); $name = get_option('blogname'); echo ''. ''; } function fbc_txt2html($raw_str) { return htmlspecialchars($raw_str, ENT_QUOTES, 'UTF-8'); } function fbc_render_like() { $permalink = fbc_current_permalink(); if (!$permalink) { return ''; } $href = urlencode($permalink); return ''; } function fbc_current_permalink() { if (!is_singular()) { return null; } global $wp_query; return get_permalink($wp_query->get_queried_object_id()); } /* * Generated and process the administrative options panel, for api key * and secret configuration. */ function fbc_admin_options() { $hidden_field_name = 'mt_submit_hidden'; // Read in existing option value from database $app_key = get_option(FBC_APP_KEY_OPTION); $app_secret = get_option(FBC_APP_SECRET_OPTION); $extensions = get_option(FBC_APP_EXTENSIONS_OPTION); $remove_nofollow = get_option(FBC_REMOVE_NOFOLLOW_OPTION); if ($remove_nofollow === false) { // set default $remove_nofollow = 'true'; update_option(FBC_REMOVE_NOFOLLOW_OPTION, $remove_nofollow); } // See if the user has posted us some information // If they did, this hidden field will be set to 'Y' if( $_POST[ $hidden_field_name ] == 'Y' ) { // Read their posted value $app_key = $_POST[FBC_APP_KEY_OPTION]; $app_secret = $_POST[FBC_APP_SECRET_OPTION]; $extensions = $_POST[FBC_APP_EXTENSIONS_OPTION]; $remove_nofollow = isset($_POST[FBC_REMOVE_NOFOLLOW_OPTION]) ? 'true' : 'false'; $error = null; if (fbc_is_app_config_valid($app_key, $app_secret, $error)) { // Save the posted value in the database update_option(FBC_APP_KEY_OPTION, $app_key); update_option(FBC_APP_SECRET_OPTION, $app_secret); update_option(FBC_APP_EXTENSIONS_OPTION, $extensions); update_option(FBC_REMOVE_NOFOLLOW_OPTION, $remove_nofollow); fbc_set_callback_url(); echo fbc_update_message(__('Options saved.', 'mt_trans_domain' )); } else { echo fbc_update_message(__("Failed to set API Key. Error: $error", 'mt_trans_domain' )); } } echo '
'; echo "

" . __( 'Facebook Connect Plugin Options', 'mt_trans_domain' ) . "

"; $form_action = str_replace('%7E', '~', $_SERVER['REQUEST_URI']); echo <<
To use Facebook Connect you will first need to get a Facebook API Key:
  1. Visit the Facebook application registration page.
  2. Enter a descriptive name for your blog in the "Application Name" field. This will be seen by users when they sign up for your site.
  3. Submit
  4. Copy the displayed API Key and Secret into this form.
  5. Recommended: Upload icon images on the app configuration page. These images are seen as the icon in newsfeed stories and when the user is registering with your application

EOF; echo fbc_tag_input('hidden', $hidden_field_name, 'Y'); echo fbc_tag_p(__("API Key:", 'mt_trans_domain'), fbc_tag_input('text', FBC_APP_KEY_OPTION, $app_key, 50)); echo fbc_tag_p(__("Secret:", 'mt_trans_domain' ), fbc_tag_input('text', FBC_APP_SECRET_OPTION, $app_secret, 50)); echo fbc_tag_p(__("Extensions:", 'mt_trans_domain' ), fbc_tag_input('text', FBC_APP_EXTENSIONS_OPTION, $extensions, 50)); echo "Enter comma seperated extensions ex: pdf,mp3,doc,xls,csv.....etc"; echo fbc_tag_p(__('Strip nofollow from Facebook comment author links:', 'mt_trans_domain'), ''); echo fbc_tag_p(__('Last user data update:', 'mt_trans_domain'), get_option(FBC_LAST_UPDATED_CACHE_OPTION)); echo "
"; echo "Latest Plugin Updates:"; echo "
"; $rss = new DOMDocument(); $rss->load('http://www.amarinfotech.com/article_feed.php'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('date')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 1; for($x=0;$x<$limit;$x++) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo '

'.$title.'
'; echo 'Posted on '.$date.'

'; echo '

'.$description.'

'; } ?>

EOF; } function fbc_register_init($app_config='reload') { $plugin_dir = this_plugin_path() . '/'; $site_url = get_option('siteurl'); $user = wp_get_current_user(); $init = "FBConnect.init('%s', '%s', '%s', %d, FBConnect.appconfig_%s);"; fbc_footer_register(sprintf($init, get_option(FBC_APP_KEY_OPTION), $plugin_dir, $site_url, $user->ID, $app_config), $prepend=true); } function _fbc_flush_footer_js() { global $onloadJS; $onloadJS[] = ''; $js = implode("\n", $onloadJS); $onloadJS = null; return << $js EOF; } function fbc_footer() { /* Normally this div is inserted by javascript via document.write(), but for XML documnts (XHTML) this fails. Workaround by including the div at page generation time. */ echo '
'; fbc_update_facebook_data(); fbc_register_init(); echo fbc_render_static_resource(); /* Only render this if it hasn't already been done elsewhere. */ if (FBC_USER_PROFILE_WINDOW && empty($GLOBALS['FBC_HAS_RENDERED_LOGIN_STATE'])) { echo '
'. fbc_render_login_state() . '
'; } echo _fbc_flush_footer_js(); echo fbc_render_debug_info(); } /* Generates the absolutely positioned box declaring who your are logged in as. */ function fbc_display_login_state() { echo fbc_render_login_state(); } function fbc_login_form() { echo fbc_render_static_resource(); $dir1 = plugins_url() . '/wp-facebookconnect/images/facebook_login.jpg'; // echo ''; // The 'none' config prevents unnessary reloads on logout fbc_register_init($appconfig='none'); if ($_GET['loggedout']) { /* Discussed in http://wiki.developers.facebook.com/index.php/Authenticating_Users_on_Facebook */ fbc_footer_register('FBConnect.logout();'); } echo _fbc_flush_footer_js(); } /* * Show debug info, if available. */ function fbc_render_debug_info() { if (!empty($GLOBALS['FBC_DEBUGINFO'])) { $dbg = $GLOBALS['FBC_DEBUGINFO']; return << $dbg EOF; } } function fbc_render_login_state() { global $FBC_HAS_RENDERED_LOGIN_STATE; $FBC_HAS_RENDERED_LOGIN_STATE = true; $fbuid = fbc_get_fbconnect_user(); if (!$fbuid ) { echo ''; return; // don't display anything if not logged in } $btn = render_fbconnect_button(); return sprintf(' ', $fbuid, $fbuid); } function fbc_comment_form_setup() { if (fbc_get_fbconnect_user()) { echo fbc_render_like(); $blogname = get_option('blogname'); $article_title = ltrim(wp_title($sep='',$display=false,$seplocation='')); global $post; $excerpt = strip_tags($post->post_content); $excerpt_len = 1024; if (strlen($excerpt) > $excerpt_len) { $excerpt = substr($excerpt, 0, $excerpt_len) . "..."; } fbc_set_js_var('excerpt', $excerpt); fbc_set_js_var('blog_name', $blogname); fbc_set_js_var('article_title', $article_title); fbc_footer_register("FBConnect.setup_feedform();"); } } function fbc_set_js_var($name, $value) { fbc_footer_register('FBConnect.'.$name .'='.json_encode($value)); } function fbc_display_login_button($hidden=false) { $user = wp_get_current_user(); if($user->ID) { // For the moment disallow connecting existing accounts return; } if ($hidden) { $visibility = 'style="visibility:hidden"'; } else { $visibility = ''; } $site_url = get_option('siteurl'); return $button = render_fbconnect_button(); /* echo <<