5; } } function wpbook_getAdminOptions() { $wpbookOptions = get_option('wpbookAdminOptions'); if (!empty($wpbookOptions)) { foreach ($wpbookOptions as $key => $option) $wpbookAdminOptions[$key] = $option; } return $wpbookAdminOptions; } function setAdminOptions($wpbook_installation, $fb_api_key, $fb_secret, $fb_app_url,$fb_admin_target,$fb_page_target,$invite_friends,$require_email, $give_credit,$enable_share, $allow_comments, $links_position,$enable_external_link, $enable_profile_link,$timestamp_date_format, $timestamp_time_format, $show_date_title, $show_advanced_options,$custom_header,$custom_footer, $show_custom_header_footer,$use_gravatar, $gravatar_rating,$gravatar_default,$show_pages, $exclude_page_list,$exclude_true,$show_pages_menu, $show_pages_list, $show_recent_post_list, $recent_post_amount,$stream_publish,$stream_publish_pages, $show_errors,$promote_external,$import_comments, $approve_imported_comments,$num_days_import, $imported_comments_email,$infinite_session_key, $attribution_line,$wpbook_enable_debug, $wpbook_use_global_gravatar,$wpbook_as_note, $wpbook_target_group, $wpbook_disable_sslverify) { $wpbookAdminOptions = array('wpbook_installation' => $wpbook_installation, 'fb_api_key' => $fb_api_key, 'fb_secret' => $fb_secret, 'fb_app_url' => $fb_app_url, 'fb_admin_target' => $fb_admin_target, 'fb_page_target' => $fb_page_target, 'invite_friends' => $invite_friends, 'require_email' => $require_email, 'give_credit' => $give_credit, 'enable_share' => $enable_share, 'allow_comments' => $allow_comments, 'links_position' => $links_position, 'enable_external_link' => $enable_external_link, 'enable_profile_link' => $enable_profile_link, 'timestamp_date_format' => $timestamp_date_format, 'timestamp_time_format' => $timestamp_time_format, 'show_date_title' => $show_date_title, 'show_advanced_options' => $show_advanced_options, 'custom_header' => $custom_header, 'custom_footer' => $custom_footer, 'show_custom_header_footer'=> $show_custom_header_footer, 'use_gravatar'=> $use_gravatar, 'gravatar_rating'=> $gravatar_rating, 'gravatar_default'=> $gravatar_default, 'show_pages'=> $show_pages, 'exclude_pages'=>$exclude_page_list, 'exclude_true'=>$exclude_true, 'show_pages_menu'=>$show_pages_menu, 'show_pages_list'=>$show_pages_list, 'show_recent_post_list'=>$show_recent_post_list, 'recent_post_amount'=>$recent_post_amount, 'stream_publish' => $stream_publish, 'stream_publish_pages' => $stream_publish_pages, 'show_errors' => $show_errors, 'promote_external' => $promote_external, 'import_comments' => $import_comments, 'approve_imported_comments' => $approve_imported_comments, 'num_days_import' => $num_days_import, 'imported_comments_email' => $imported_comments_email, 'infinite_session_key' => $infinite_session_key, 'attribution_line' => $attribution_line, 'wpbook_enable_debug' => $wpbook_enable_debug, 'wpbook_use_global_gravatar' => $wpbook_use_global_gravatar, 'wpbook_as_note' => $wpbook_as_note, 'wpbook_target_group' => $wpbook_target_group, 'wpbook_disable_sslverify' => $wpbook_disable_sslverify, ); update_option('wpbookAdminOptions', $wpbookAdminOptions); } add_action('admin_menu', 'wpbook_options_page'); function wpbook_options_page() { if (function_exists('add_options_page')) { $wpbook_plugin_page = add_options_page('WPBook', 'WPBook', 8, basename(__FILE__), 'wpbook_subpanel'); add_action( 'load-'. $wpbook_plugin_page, 'wpbook_admin_head' ); } } //function to add css and java to the header of the admin page function wpbook_admin_head() { $plugin_url= WP_PLUGIN_URL; wp_enqueue_script('wpbook_admin_javascript.js', $plugin_url.'/wpbook/admin_includes/wpbook_admin_javascript.js'); wp_enqueue_style('wpbook_admin_styles.css', $plugin_url.'/wpbook/admin_includes/wpbook_admin_styles.css'); } //function to list pages to exclude taken from List Pages Plus function wpbook_exclude_Page(){ global $wpdb; $wpbookAdminOptions = wpbook_getAdminOptions(); $pages = $wpdb->get_results( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' ORDER BY post_parent, menu_order, post_title ASC" ); $select = $wpbookAdminOptions['exclude_pages']; $select = explode(",", $select); $out = ""; echo $out; } function wpbook_subpanel() { if (is_authorized()) { global $current_user; get_currentuserinfo(); $wpbookAdminOptions = wpbook_getAdminOptions(); if (isset($_POST['fb_api_key']) && isset($_POST['fb_secret']) && isset($_POST['fb_app_url']) && isset($_POST['fb_admin_target']) && (!empty($_POST['fb_api_key'])) && (!empty($_POST['fb_secret'])) && (!empty($_POST['fb_app_url'])) && (!empty($_POST['fb_admin_target']))) { $fb_api_key = preg_replace("#[^0-9]#", "",$_POST['fb_api_key']); $fb_secret = $_POST['fb_secret']; $fb_app_url = $_POST['fb_app_url']; $fb_admin_target = preg_replace("#[^0-9]#", "",$_POST['fb_admin_target']); $fb_page_target = preg_replace("#[^0-9]#", "",$_POST['fb_page_target']); $invite_friends = $_POST['invite_friends']; $require_email = $_POST['require_email']; $give_credit = $_POST['give_credit']; $enable_share = $_POST['enable_share']; $allow_comments = $_POST['allow_comments']; $links_position = $_POST['links_position']; $enable_external_link = $_POST['enable_external_link']; $enable_profile_link = $_POST['enable_profile_link']; // Handle custom date/time formats code modified from wp-admin/options.php if ( !empty($_POST['timestamp_date_format']) && isset($_POST['timestamp_date_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['timestamp_date_format'] ) ) $_POST['timestamp_date_format'] = $_POST['timestamp_date_format_custom']; if ( !empty($_POST['timestamp_time_format']) && isset($_POST['timestamp_time_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['timestamp_time_format'] ) ) $_POST['timestamp_time_format'] = $_POST['timestamp_time_format_custom']; //end custom date/time code $timestamp_date_format = $_POST['timestamp_date_format']; $timestamp_time_format = $_POST['timestamp_time_format']; $show_date_title = $_POST['show_date_title']; $show_advanced_options = $_POST['show_advanced_options']; $custom_header = $_POST['custom_header']; $custom_footer = $_POST['custom_footer']; $show_custom_header_footer = $_POST['show_custom_header_footer']; $use_gravatar = $_POST['use_gravatar']; $gravatar_rating = $_POST['gravatar_rating']; $show_pages = $_POST['show_pages']; $exclude_true = $_POST['exclude_true']; $show_pages_menu = $_POST['show_pages_menu']; $show_pages_list = $_POST['show_pages_list']; $show_recent_post_list = $_POST['show_recent_post_list']; $recent_post_amount = preg_replace("#[^0-9]#", "",$_POST['recent_post_amount_input']); $stream_publish = $_POST['stream_publish']; $stream_publish_pages = $_POST['stream_publish_pages']; $show_errors = $_POST['show_errors']; $promote_external = $_POST['promote_external']; $import_comments = $_POST['import_comments']; $approve_imported_comments = $_POST['approve_imported_comments']; $num_days_import = preg_replace("#[^0-9]#", "",$_POST['num_days_import']); $imported_comments_email = $_POST['imported_comments_email']; $infinite_session_key = $_POST['infinite_session_key']; $attribution_line = $_POST['attribution_line']; $wpbook_enable_debug = $_POST['wpbook_enable_debug']; $wpbook_as_note = $_POST['wpbook_as_note']; $wpbook_target_group = $_POST['wpbook_target_group']; $wpbook_disable_sslverify = $_POST['wpbook_disable_sslverify']; $wpbook_use_global_gravatar = $_POST['wpbook_use_global_gravatar']; // Handle custom gravatar_deault code modified from wp-admin/options.php if ( !empty($_POST['gravatar_default']) && isset($_POST['gravatar_rating_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['gravatar_default'] ) ) $_POST['gravatar_default'] = $_POST['gravatar_rating_custom']; //end custom gravatar_deafult code $gravatar_default = $_POST['gravatar_default']; $exclude_pages = $_POST['exclude_pages']; //write a comma seperated list of pages to exclude $exclude_pages_count = count($exclude_pages); $i = 0; if (!empty($exclude_pages)) { foreach($exclude_pages as $page_id) { $i++; $exclude_page_list .= $page_id ; if($i<$exclude_pages_count){ $exclude_page_list .= ','; } } } setAdminOptions(1, $fb_api_key, $fb_secret, $fb_app_url,$fb_admin_target,$fb_page_target, $invite_friends,$require_email,$give_credit,$enable_share, $allow_comments,$links_position,$enable_external_link, $enable_profile_link,$timestamp_date_format, $timestamp_time_format,$show_date_title, $show_advanced_options,$custom_header,$custom_footer, $show_custom_header_footer,$use_gravatar,$gravatar_rating, $gravatar_default,$show_pages,$exclude_page_list, $exclude_true,$show_pages_menu,$show_pages_list, $show_recent_post_list, $recent_post_amount,$stream_publish, $stream_publish_pages,$show_errors,$promote_external, $import_comments,$approve_imported_comments,$num_days_import, $imported_comments_email,$infinite_session_key, $attribution_line,$wpbook_enable_debug, $wpbook_use_global_gravatar,$wpbook_as_note, $wpbook_target_group,$wpbook_disable_sslverify); $flash = "Your settings have been saved. "; } elseif (($wpbookAdminOptions['fb_api_key'] != "") && ($wpbookAdminOptions['fb_secret'] != "") && ($wpbookAdminOptions['fb_app_url'] != "") && ($wpbookAdminOptions['fb_admin_target'] != "") && (!empty($_POST['fb_api_key'])) && (!empty($_POST['fb_secret'])) && (!empty($_POST['fb_app_url'])) && (!empty($_POST['fb_admin_target']))){ $flash = ""; } else { $flash = "Please complete all necessary fields";} } else { $flash = "You don't have enough access rights."; } if (is_authorized()) { $wpbookAdminOptions = wpbook_getAdminOptions(); //set the "smart" defaults on install this only works once the page has been refeshed if ($wpbookAdminOptions['wpbook_installation'] != 1) { $gravatar_default = WP_PLUGIN_URL .'/wpbook/theme/default/gravatar_default.gif'; setAdminOptions(1, null,null,null,null,null,true,true,true,true,true,top,null,null,"F j, Y","g:i a", true,null,null,null,disabled,null,"g",$gravatar_default,null,null,null,null,true,true,10, false,false,false,false,false,false,7,"facebook@openparenthesis.org",null,null,null,false,false,null,false); } if ($flash != '') echo '
' . '

' . $flash . '

'; $plugin_url = WP_PLUGIN_URL.'/wpbook'; ?>

WPBook Setup

This plugin allows you to embed your blog into the Facebook canvas, allows Facebook users to comment on or share your blog posts, cross-posts your blog posts to the wall of your profile, a fan page, an application profile page, or a group page, and enables you to add a tab for your fan page. It also imports comments made against wall posts which originated in WordPress.

Detailed instructions

If you are having issues, please begin by Checking ' . 'permissions for stream publishing, reading, and offline access.

'; } ?>

Required Settings +

To use this plugin, you must create a Facebook application. After you've obtained the necessary info, fill in both your application's App_ID and Secret keys as well as your application's url and your Facebook profile ID.

Note: Your "Canvas Callback URL" setting in Facebook should be: ' . get_bloginfo('url') . '

'; echo '
'; echo '

Facebook App ID: '; if(!empty($wpbookAdminOptions['fb_api_key'])) { echo ' Visit this app profile'; } echo '

'; echo '

Facebook App Secret: '; echo '

'; echo '

YOUR Facebook Profile ID: '; if(!empty($wpbookAdminOptions['fb_admin_target'])) { echo ' visit this profile'; } echo '

Note: if you don\'t know your ID you can get it by visiting http://graph.facebook.com/YOUR_USERNAME
Replacing the "YOUR_USERNAME" with your Facbook login. (More info on finding your Page ID).'; echo '

'; echo '

Facebook Canvas Page URL, '; echo 'NOT INCLUDING "http://apps.facebook.com/" '; echo ''; if(!empty($wpbookAdminOptions['fb_app_url'])) { echo ' Visit this canvas page'; } echo '

'; ?>

Stream/Wall Options +

Once your Facebook application is established by filling out the required information, return to edit streaming options.

'; } else { echo '

These settings all impact how WPBook publishes to Facebook walls, and depend on appropriate permissions being set in Facebook.

'; echo '

If you are having issues, please begin by Checking ' . 'permissions for stream publishing, reading, and offline access.

'; echo '

Stream Profile/Page Options

Publish new posts to YOUR Facebook Wall

'; echo '

Publish as Notes (rather than excerpts - applies only to individual profiles)

'; echo '

Publish new posts to the wall of this page/group: '; echo '

Page ID: '; echo ' (Information on finding your Page ID)

'; echo '

Group ID: '; echo ' (Generally your GroupID should be in your url, like: http://www.facebook.com/group.php?gid=149948248362737 - the gid is the group ID).

'; echo '

Use external permalinks on Walls (applies to profiles, pages, and groups)

'; /* using the new Graph API, there's nowhere to put attribution strings * So I'm just hiding this for now */ //echo '

Attribution line:
'; //echo 'Predefined Strings (you can use these in your attribution line): %author%, %blogname%.

'; echo '

Stream Debug Options
Enable WPBook to create a debug file'; echo '
Show errors posting to Facebook Stream

'; echo '

Disable Facebook SSL verification

'; echo '

Stream Comment Options
Import comments from Facebook Walls
'; echo '

Automatically approve imported Wall comments

'; echo '

For how many days should WPBook look for comments on Facebook Walls?: '; echo ' 

'; echo '

What email address should WPBook associate with imported comments? '; echo ' 

'; echo '
'; } //end hide all settings if required fields aren't filled in ?>

Application View Options+

Once your Facebook application is established by filling out the required information, return to customize your application view.

'; } else { echo '

These settings all impact what the users of your application see inside of Facebook. In your case what they see by visiting http://apps.facebook.com/' . htmlentities($wpbookAdminOptions['fb_app_url']).'

'; /* Now let's handle commenting - only show require_email if comments on */ echo'

Commenting Options:

'; echo '

Allow comments inside Facebook

'; echo '
Require Comment Authors E-mail Address'; //gravatar options echo '
Show Gravatar Images'; //gravatar rating echo '

Gravatar Rating: '; $gravatar_ratings = array('G','PG','R','X'); foreach ( $gravatar_ratings as $gravatar_rating ) { echo " ' . $gravatar_rating; } //gravatar default echo '

Gravatar Default:

'; echo '

Facebook Default '); $gravatar_defaults = array('identicon','monsterid','wavatar'); foreach ( $gravatar_defaults as $gravatar_default ) { echo " ' . $gravatar_default; echo ' '; } //Custom Gravatar echo ' Custom:

'; //gravatar outside Facebook echo'

Use WPBook Gravatar Globally (this will overwrite WordPress Gravatar settings and also show Facebook avatars outside of Facebook)'; echo'

'; echo '

Socialize Options:

'; // Here starts the "invite friends" section echo '

Show Invite Friends Link

'; // removed enabled add-to-profile option as Facebook no longer supports // this for normal users. You can still add a tab to Fan Pages, but you // don't need the button for that // show share option echo '

Enable "Share This Post" (within Facebook)

'; // show external link option echo '

Enable "view post at external site" link

'; //links button position for external and share button //see if share button or external link is enabled first echo '

Link(s) position for share button and external link button: '; //top echo 'Top '; echo ' Bottom

'; echo'

Page Options:

'; //start show pages option echo '

Enable pages

'; echo '
'; //show top menu of parent pages echo'

Display menu of parent pages at top of application

Show a list of pages below content

'; echo '
'; echo ' Exclude some pages
'; echo(wpbook_exclude_Page()); echo'
'; //end exclude pages echo'
'; //end bottom page list echo '
'; //end all page options echo'

General Options:

'; //start show date in title echo '

Include post date with title ' .'

'; echo ' Date Format:

'; // date code copied from wp-admin/options-general.php $date_formats = apply_filters( 'date_formats', array( __('F j, Y'), 'Y/m/d', 'm/d/Y', 'd/m/Y', ) ); $custom = TRUE; foreach ( $date_formats as $format ) { echo "\t
\n"; } echo ' ' . date_i18n($wpbookAdminOptions['timestamp_date_format'], time(),FALSE); echo'

'; //end date code //start time code, copied from wp-admin/options-general.php echo ' Time format

'; $time_formats = apply_filters( 'time_formats', array( __('g:i a'), 'g:i A', 'H:i', ) ); $custom = TRUE; foreach ( $time_formats as $format ) { echo "\t
\n"; } echo ' ' . date_i18n(($wpbookAdminOptions['timestamp_time_format']), time(),FALSE ) . "\n"; echo "\t

" . __('Documentation on date/time formatting. Click "Save" to update sample output.'). "

\n"; echo '
'; //start give credit option echo '

Give WPBook Credit (in Facebook)

' .'

Show a list of recent post below content

' .'

How many?

'; echo '

Custom Header and Footer
This is where you can' .' set custom headers and footers for your post. For example if you wanted' .' to show the post author at the bottom of each post here is where you would set that option.'; //enable custom footer/header echo '

Show Custom Header/Footer:
'; //disabled echo 'Disabled '; //Both echo ' Both '; //header echo ' Header '; //footer echo ' Footer

'; echo''); }//end valid required settings ?>

'; echo'
'; echo '

Need Help?

'; echo '

If you need help setting up this application first read the install instructions.'; echo 'Support can also be found on the plugin page

Thanks for using WPBook!

'; echo'
'; } else { echo '

Sorry, you are not allowed to access '; echo 'this page.

'; } } if (!function_exists('wp_recent_posts')) { // this is based almost entirely on: Recent Posts // http://mtdewvirus.com/code/wordpress-plugins/ v. 1.07 // by Nick Momrik, http://mtdewvirus.com/ function wp_recent_posts($count = 5, $before = '
  • ', $after = '
  • ', $hide_pass_post = true, $skip_posts = 0, $show_excerpts = false, $where = '', $join = '', $groupby = '') { global $wpdb; $time_difference = get_settings('gmt_offset'); $now = gmdate("Y-m-d H:i:s",time()); $join = apply_filters('posts_join', $join); $where = apply_filters('posts_where', $where); $groupby = apply_filters('posts_groupby', $groupby); if (!empty($groupby)) { $groupby = ' GROUP BY '.$groupby; } $request = "SELECT ID, post_title, post_excerpt FROM $wpdb->posts " . "$join WHERE post_status = 'publish' AND post_type = 'post' "; if ($hide_pass_post) $request .= "AND post_password ='' "; $request .= "AND post_date_gmt < '$now' $where $groupby ORDER BY " . "post_date DESC LIMIT $skip_posts, $count"; $posts = $wpdb->get_results($request); $output = ''; if ($posts) { foreach ($posts as $post) { $post_title = stripslashes($post->post_title); $permalink = get_permalink($post->ID); $output .= $before . '' . $post_title . ''; if($show_excerpts) { $post_excerpt = stripslashes($post->post_excerpt); $output.= '
    ' . $post_excerpt; } $output .= $after; } } else { $output .= $before . "None found" . $after; } echo $output; } } // todo: eliminate this function (not needed anymore?) // this is a copy of the wp_recent_posts function // necessary because we don't want to echo output (for profile) function wpbook_profile_recent_posts($count = 5, $before = '
  • ', $after = '
  • ', $hide_pass_post = true, $skip_posts = 0, $show_excerpts = false, $where = '', $join = '', $groupby = '') { global $wpdb; $my_options = wpbook_getAdminOptions(); $time_difference = get_settings('gmt_offset'); $now = gmdate("Y-m-d H:i:s",time()); $join = apply_filters('posts_join', $join); $where = apply_filters('posts_where', $where); $groupby = apply_filters('posts_groupby', $groupby); if (!empty($groupby)) { $groupby = ' GROUP BY '.$groupby; } $request = "SELECT ID, post_title, post_excerpt FROM $wpdb->posts " . "$join WHERE post_status = 'publish' AND post_type = 'post' "; if ($hide_pass_post) $request .= "AND post_password ='' "; $request .= "AND post_date_gmt < '$now' $where $groupby ORDER BY " . "post_date DESC LIMIT $skip_posts, $count"; $posts = $wpdb->get_results($request); $output = ''; if ($posts) { foreach ($posts as $post) { $post_title = stripslashes($post->post_title); if($my_options['promote_external']) { if(check_facebook()) { $permalink = get_external_post_url(get_permalink($post->ID)); // external permalink } else { $permalink = get_permalink($post->ID); } } else { $permalink = get_permalink($post->ID); // permalink is un-filtered $my_offset = strlen(get_option('home')); $app_url = $my_options['fb_app_url']; $my_link = 'http://apps.facebook.com/' . $app_url . substr($permalink,$my_offset); $permalink = $my_link; } $output .= $before . '' . $post_title . ''; if($show_excerpts) { $post_excerpt = stripslashes($post->post_excerpt); $output.= '
    ' . $post_excerpt; } $output .= $after; } } else { $output .= $before . "None found" . $after; } return $output; } // this checks to see if we are in facebook function check_facebook() { if (!isset($_SERVER["HTTP_USER_AGENT"])) { return false; } if (isset($_REQUEST['fb_sig_in_iframe']) || isset($_REQUEST['fb_force_mode'])) { defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', 'true'); return true; } /* need to check for signed_request to trap new iframes */ if (isset($_POST['signed_request']) || isset($_REQUEST['signed_request'])) { defined('DONOTCACHEPAGE') or define('DONOTCACHEPAGE', 'true'); return true; } return false; } function wpbook_theme_root($path) { $theme_root = dirname(__FILE__); if (check_facebook()) { if(wpbook_check_custom_theme('WPBook')) { $path = WP_CONTENT_DIR . '/themes/wpbook_theme'; return $path; } else{ return $theme_root . '/theme'; } } else { return $path; } } function wpbook_theme_root_uri($url) { if (check_facebook()){ if(wpbook_check_custom_theme('WPBook')) { //apparently get_theme_dir() returns a 500 error $dir = WP_CONTENT_URL . '/themes/wpbook_theme'; return $dir; } else{ $dir = WP_PLUGIN_ULR . '/wpbook/theme'; return $dir; } } else { return $url; } } function wpbook_stylesheet($url) { if (check_facebook()){ if(wpbook_check_custom_theme('WPBook')) { return 'default'; } } else { return $url; } } // this function seems to be required by WP 2.6 function wpbook_template_directory($value) { if (check_facebook()) { if(wpbook_check_custom_theme('WPBook')){ $theme_root = WP_CONTENT_DIR . '/themes/wpbook_theme'; return $theme_root; } else{ $theme_root = WP_PLUGIN_DIR; return $theme_root . '/wpbook/theme'; } } else { return $value; } } //check to see if the user has a custom theme in their theme folder function wpbook_check_custom_theme($theme) { global $wp_version; if (version_compare($wp_version, '3.1', '>=')) { // get_themes() crashes WP < 3.1 $installed_themes= array(); $installed_themes= get_themes(); $wpbook_theme_check = (!empty($installed_themes[$theme])) ? TRUE : FALSE; return $wpbook_theme_check; } else { // this check works before 3.1 if(file_exists(WP_CONTENT_DIR . '/themes/wpbook_theme/style.css')){ return TRUE; } } return FALSE; // no custom theme found } // this is the function which adds to the template and stylesheet hooks // the call to wpbook_template if (check_facebook()) { add_filter('template_directory', 'wpbook_template_directory'); add_filter('theme_root', 'wpbook_theme_root'); add_filter('theme_root_uri', 'wpbook_theme_root_uri'); add_filter('stylesheet', 'wpbook_stylesheet'); } // also have to change permalinks, next/prev links , page links, and archive links function fb_filter_postlink($postlink) { if (check_facebook()) { $my_offset = strlen(get_option('home')); $my_options = wpbook_getAdminOptions(); $app_url = $my_options['fb_app_url']; $my_link = 'http://apps.facebook.com/' . $app_url . substr($postlink,$my_offset); return $my_link; } else { return $postlink; } } function fb_filter_postlink_no_qs($postlink) { if (check_facebook()) { $my_offset = strlen(get_option('home')); $my_options = wpbook_getAdminOptions(); $app_url = $my_options['fb_app_url']; $my_link = 'http://apps.facebook.com/' . $app_url . substr($postlink,$my_offset); $my_new_link_pieces = parse_url($my_link); return parse_url($my_link,PHP_URL_SCHEME) .'://'. parse_url($my_link,PHP_URL_HOST) . parse_url($my_link,PHP_URL_PATH); // ignoring port } else { return $postlink; } } // this version to be called when we're outside facebook too function wpbook_always_filter_postlink($postlink) { $my_offset = strlen(get_option('home')); $my_options = wpbook_getAdminOptions(); $app_url = $my_options['fb_app_url']; $my_link = 'http://apps.facebook.com/' . $app_url . substr($postlink,$my_offset); return $my_link; } /* * This function handles streaming publish to Facebook. * It includes publish_to_facebook.php */ function wpbook_publish_to_facebook($post_ID) { if (!version_compare(PHP_VERSION, '5.0.0', '<')) { include(WP_PLUGIN_DIR .'/wpbook/includes/publish_to_facebook.php'); } else { wp_die("Sorry, but you can't run this plugin, it requires PHP 5 or higher."); } wpbook_safe_publish_to_facebook($post_ID); } // end of function wpbook_publish_to_facebook function get_external_post_url($my_permalink){ $my_options = wpbook_getAdminOptions(); $app_url = $my_options['fb_app_url']; // code to get the url of the orginal post for use in the "show external url view" $permalink_pieces = parse_url($my_permalink); //get the app_url and the preceeding slash $permalink_app_url = "/". $app_url; //remove /appname $external_post_permalink = str_replace_once($permalink_app_url,"",$permalink_pieces[path]); //re-write the post url using the site url $external_site_url_pieces = parse_url(get_bloginfo('wpurl')); //break apart the external site address and get just the "site.com" part $external_site_url = $external_site_url_pieces[host]; $external_post_url = get_bloginfo('siteurl'). $external_post_permalink; if(!empty($permalink_pieces[query])) { $external_post_url = $external_post_url .'?'. $permalink_pieces[query]; } //return "app url is " . $app_url; return $external_post_url; } // check to see if external post link contains the app name, and if it does, // only replace the first instance function str_replace_once($needle, $replace, $haystack) { // Looks for the first occurence of $needle in $haystack // and replaces it with $replace. $pos = strpos($haystack, $needle); if ($pos === false) { // Nothing found return $haystack; } return substr_replace($haystack, $replace, $pos, strlen($needle)); } // attribution line function wpbook_attribution_line($attribution_line,$author){ if($author == '') { $author = get_the_author(); } $attribution_line = str_replace('%author%',$author,$attribution_line); $attribution_line = str_replace('%blogname%',html_entity_decode(get_bloginfo('name'),ENT_QUOTES),$attribution_line); return $attribution_line; } /* * Use postmeta to enable users to turn off streaming on case-by-case basis * Based on how Alex King's Twitter Tools handles the same case for pushing * posts to twitter */ function wpbook_meta_box() { global $post; $wpbook_publish = get_post_meta($post->ID, 'wpbook_fb_publish', true); if ($wpbook_publish == '') { $wpbook_publish = 'yes'; } echo '

    '.__('Publish this post to Facebook Wall?', 'wpbook').'
    '; echo '   '; echo ' '; echo '

    '; do_action('wpbook_post_options'); } function wpbook_add_meta_box() { global $wp_version; if (version_compare($wp_version, '2.7', '>=')) { add_meta_box('wpbook_post_form','WPBook', 'wpbook_meta_box', 'post', 'side'); } else { add_meta_box('wpbook_post_form','WPBook', 'wpbook_meta_box', 'post', 'normal'); } } function wpbook_store_post_options($post_id, $post = false) { if (!$post || $post->post_type == 'revision') { // store the metadata with the post, not the revision return; } $wpbookAdminOptions = wpbook_getAdminOptions(); $post = get_post($post_id); $stored_meta = get_post_meta($post_id, 'wpbook_fb_publish', true); $posted_meta = $_POST['wpbook_fb_publish']; $save = false; /* if there is $posted_meta, that takes priority over stored */ if (!empty($posted_meta)) { $posted_meta == 'yes' ? $meta = 'yes' : $meta = 'no'; $save = true; } /* if no posted meta, check stored meta */ else if (empty($stored_meta)) { /* if no stored meta, but streaming publishing is on, default to yes */ if (($wpbookAdminOptions['stream_publish']) || ($wpbookAdminOptions['stream_publish_pages'])) { $meta = 'yes'; } else { $meta = 'no'; } $save = true; /* if there is stored meta, and user didn't touch it, don't save */ } else { $save = false; } if ($save) { if (!update_post_meta($post_id, 'wpbook_fb_publish', $meta)) { add_post_meta($post_id, 'wpbook_fb_publish', $meta); } } } add_action('draft_post', 'wpbook_store_post_options', 1, 2); add_action('publish_post', 'wpbook_store_post_options', 1, 2); add_action('save_post', 'wpbook_store_post_options', 1, 2); // based on sample code here: // http://willnorris.com/2009/06/wordpress-plugin-pet-peeve-2-direct-calls-to-plugin-files // thanks will function wpbook_parse_request($wp) { if (array_key_exists('wpbook', $wp->query_vars)){ if($wp->query_vars['wpbook'] == 'comment-handler') { // first process requests with "wpbook=comment-handler" // process the request - in our case this is a comment being posted nocache_headers(); $comment_post_ID = (int) $_POST['comment_post_ID']; global $wpdb; $status = $wpdb->get_row("SELECT post_status, comment_status FROM " . "$wpdb->posts WHERE ID = '$comment_post_ID'"); if ( empty($status->comment_status) ) { do_action('comment_id_not_found', $comment_post_ID); exit; } elseif ( !comments_open($comment_post_ID) ) { do_action('comment_closed', $comment_post_ID); wp_die( __('Sorry, comments are closed for this item.') ); } elseif ( in_array($status->post_status, array('draft', 'pending') ) ) { do_action('comment_on_draft', $comment_post_ID); exit; } $wpbookOptions = get_option('wpbookAdminOptions'); if (!empty($wpbookOptions)) { foreach ($wpbookOptions as $key => $option) $wpbookAdminOptions[$key] = $option; } $comment_author = trim(strip_tags($_POST['author'])); $comment_author_email = trim($_POST['email']); $comment_author_url = trim($_POST['url']); $comment_content = trim($_POST['comment']); $comment_type = ''; $wpbook_require_email = $wpbookOptions['require_email']; // need to account here for wpadminOptions version of email required if(($wpbook_require_email == "true") && ('' == $comment_author_email)){ echo '

    Sorry: comments require an email address

    '; wp_die( __('Error: please enter an e-mail.')); } if($comment_author_email != ''){ if(!preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|' . 'info|name|aero|biz|info|jobs|museum|name|edu)$/i', $comment_author_email)) { wp_die( __('Error: please enter a valid e-mail.')); } } if ( '' == $comment_content ) wp_die( __('Error: please type a comment.') ); $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID'); $comment_id = wp_new_comment( $commentdata ); $comment = get_comment($comment_id); if ( !$user->ID ) { setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); } // all done parsing, redirect to post, on comment anchor $redirect_url = get_permalink($comment_post_ID); $redirect_url .= '#comment-' . $comment_id; // switched to raw php header redirect as $facebook->redirect was // problematic and no fb session needed in this page header( 'Location: ' . $redirect_url ); } } } function wpbook_query_vars($vars) { $vars[] = 'wpbook'; return $vars; } //show facebook avatar as gravatar function wpbook_get_facebook_avatar($avatar, $comment, $size="50") { $wpbookOptions = get_option('wpbookAdminOptions'); if (!empty($wpbookOptions)) { foreach ($wpbookOptions as $key => $option) $wpbookAdminOptions[$key] = $option; } if($wpbookAdminOptions['use_gravatar'] =="true"){ $author_url = get_comment_author_url(); $email = get_comment_author_email(); $default = $wpbookAdminOptions['gravatar_default']; $rating=$wpbookAdminOptions['gravatar_rating']; $size="50"; if(preg_match("@^(?:http://)?(?:www\.)?facebook@i",trim($author_url))){ $parse_author_url = (parse_url($author_url)); $parse_author_url_q = $parse_author_url['query']; if(preg_match('/id[=]([0-9]*)/', $parse_author_url_q, $match)){ $fb_id = "/".$match[1]; } else { /* have to account here for multiple options * http://facebook.com/profile.php?id=12234 * http://www.facebook.com/pages/PageName/1234 * Application pages, groups? */ if(strrpos($parse_author_url['path'],'pages')) { $fb_id_array = explode('/',$parse_author_url['path']); $size = count($fb_id_array); $fb_id = "/" . $fb_id_array[$size-1]; } else { $fb_id = $parse_author_url['path']; } } $grav_url= "http://graph.facebook.com".$fb_id."/picture?type=square"; } else{ $grav_url = "http://www.gravatar.com/avatar/" . md5(strtolower($email))."?d=" . $default."&s=".$size."&r=".$rating; } $grav_img = ""; return $grav_img; } return $avatar; } // show facebook avatar as gravatar even outside facebook function wpbook_get_global_facebook_avatar($avatar, $comment, $size="50") { $wpbookOptions = get_option('wpbookAdminOptions'); if (!empty($wpbookOptions)) { foreach ($wpbookOptions as $key => $option) $wpbookAdminOptions[$key] = $option; } if(($wpbookAdminOptions['use_gravatar'] =="true") && ($wpbookAdminOptions['wpbook_use_global_gravatar'] =="true")){ $author_url = get_comment_author_url(); $email = get_comment_author_email(); $default = $wpbookAdminOptions['gravatar_default']; $rating=$wpbookAdminOptions['gravatar_rating']; $size="50"; $parse_author_url = (parse_url($author_url)); if(preg_match("@^(?:http://)?(?:www\.)?facebook@i",trim($author_url))){ $parse_author_url_q = $parse_author_url['query']; if(preg_match('/id[=]([0-9]*)/', $parse_author_url_q, $match)){ $fb_id = "/".$match[1]; } else { /* have to account here for multiple options * http://facebook.com/profile.php?id=12234 * http://www.facebook.com/pages/PageName/1234 * Application pages, groups? */ if(strrpos($parse_author_url['path'],'pages')) { $fb_id_array = explode('/',$parse_author_url['path']); $size = count($fb_id_array) -1; $fb_id = "/" . $fb_id_array[$size]; } else { $fb_id = $parse_author_url['path']; } } $grav_url= "http://graph.facebook.com".$fb_id."/picture?type=square"; } else { $grav_url = "http://www.gravatar.com/avatar/" . md5(strtolower($email)). "?d=" . $default."&s=".$size."&r=".$rating; } $grav_img = ""; return $grav_img; } return $avatar; } /** * Thanks Otto - http://lists.automattic.com/pipermail/wp-hackers/2009-July/026759.html */ function wpbook_activation_check(){ global $wp_version; if (version_compare(PHP_VERSION, '5.0.0', '<')) { deactivate_plugins(basename(__FILE__)); // Deactivate ourself wp_die("Sorry, but you can't run this plugin, it requires PHP 5 or higher."); } if (version_compare($wp_version, '2.9', '<')) { wp_die("This plugin requires WordPress 2.6 or greater."); } } add_filter('query_vars', 'wpbook_query_vars'); add_filter('post_link','fb_filter_postlink',1,1); add_filter('page_link','fb_filter_postlink',1,1); add_filter('get_pagenum_link','fb_filter_postlink_no_qs',1,1); //add gravatar/facebook avatar support outside facebook //filter for inside facebook is in the theme/config_wp_settings.php add_filter('get_avatar','wpbook_get_global_facebook_avatar', 1, 3 ); /* you can't actually filter the tag_link and category_links this way * because if you do, wordpress redirects to /app_url/tag/yourtag whenever * you try to access /tag/yourtag inside FB * add_filter('tag_link','fb_filter_postlink',1,1); * add_filter('category_link','fb_filter_postlink',1,1); */ add_action('admin_menu', 'wpbook_options_page'); add_action('wp', 'wpbook_parse_request'); add_action('admin_menu', 'wpbook_add_meta_box'); // these capture new posts, not edits of previous posts add_action('future_to_publish','wpbook_publish_to_facebook'); add_action('new_to_publish','wpbook_publish_to_facebook'); add_action('draft_to_publish','wpbook_publish_to_facebook'); add_action('pending_to_publish','wpbook_publish_to_facebook'); // cron job task add_action('wpbook_cron_job', 'wpbook_import_comments'); register_activation_hook(__FILE__, 'wpbook_activate'); register_deactivation_hook(__FILE__, 'wpbook_deactivate'); ?>