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,$invite_friends,$require_email,$give_credit,
$enable_share, $allow_comments,$links_position,$enable_external_link,$enable_profile_link) {
$wpbookAdminOptions = array('wpbook_installation' => $wpbook_installation,
'fb_api_key' => $fb_api_key,
'fb_secret' => $fb_secret,
'fb_app_url' => $fb_app_url,
'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);
update_option('wpbookAdminOptions', $wpbookAdminOptions);
}
function wpbook_options_page() {
if (function_exists('add_options_page')) {
add_options_page('WPBook', 'WPBook', 8,
basename(__FILE__), 'wpbook_subpanel');
}
}
function wpbook_subpanel() {
if (is_authorized()) {
$wpbookAdminOptions = wpbook_getAdminOptions();
if (isset($_POST['fb_api_key']) && isset($_POST['fb_secret']) && isset($_POST['fb_app_url'])
&& (!empty($_POST['fb_api_key'])) && (!empty($_POST['fb_secret'])) && (!empty($_POST['fb_app_url']))) {
$fb_api_key = $_POST['fb_api_key'];
$fb_secret = $_POST['fb_secret'];
$fb_app_url = $_POST['fb_app_url'];
$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'];
setAdminOptions(1, $fb_api_key, $fb_secret, $fb_app_url,
$invite_friends,$require_email,$give_credit,$enable_share,$allow_comments,$links_position,$enable_external_link,$enable_profile_link);
$flash = "Your settings have been saved. ";
}
elseif (($wpbookAdminOptions['fb_api_key'] != "") || ($wpbookAdminOptions['fb_secret'] != "") || ($wpbookAdminOptions['fb_app_url'] != "")
|| (!empty($_POST['fb_api_key'])) || (!empty($_POST['fb_secret'])) || (!empty($_POST['fb_app_url']))){
$flash = "";
}
else {$flash = "Please complete all necessary fields";}
} else {
$flash = "You don't have enough access rights.";
}
if (is_authorized()) {
$wpbookAdminOptions = wpbook_getAdminOptions();
if ($wpbookAdminOptions['wpbook_installation'] != 1) {
setAdminOptions(1, null,null,null,null,null,null,null,null,null,null,null);
}
if ($flash != '') echo '
';
// jquery functions to replace the old hid show div functions
// this should also probally be refactord to make it smaller at some point
?>
';
echo 'Set Up Your Facebook Application
';
echo 'This plugin allows you to embed your blog into the Facebook canvas';
echo ', allows Facebook users to comment on or share your blog posts, and ';
echo 'puts your 5 most recent posts in users profiles (with their permission).
';
echo 'Detailed instructions, with screenshots
';
echo '';
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 != 'page' ";
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 . ''
. htmlspecialchars($post_title) . '';
if($show_excerpts) {
$post_excerpt = stripslashes($post->post_excerpt);
$output.= '
' . $post_excerpt;
}
$output .= $after;
}
} else {
$output .= $before . "None found" . $after;
}
echo $output;
}
}
// 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;
$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 != 'page' ";
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 . ''
. htmlspecialchars($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($_GET['fb_sig_in_iframe']) || isset($_GET['fb_force_mode'])) {
return true;
}
return false;
}
function wpbook_theme_root($path) {
$theme_root = dirname(__FILE__);
if (check_facebook()) {
return $theme_root . '/theme';
} else {
return $path;
}
}
function wpbook_theme_root_uri($url) {
if (check_facebook()) {
$dir = get_bloginfo('wpurl') . "/wp-content/plugins/wpbook/theme";
return $dir;
} else {
return $url;
}
}
// this function seems to be required by WP 2.6
function wpbook_template_directory($value) {
if (check_facebook()) {
$theme_root = dirname(__FILE__);
return $theme_root . '/theme';
} else {
return $value;
}
}
// 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');
}
// also have to change permalinks and next/prev links and more 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 wp_update_profile_boxes() {
if(!class_exists('FacebookRestClient')) {
if (version_compare(PHP_VERSION,'5','>=')) {
include_once(ABSPATH.'wp-content/plugins/wpbook/client/facebook.php');
} else {
include_once(ABSPATH.'wp-content/plugins/wpbook/php4client/'
. 'facebook.php');
include_once(ABSPATH.'wp-content/plugins/wpbook/php4client/'
. 'facebookapi_php4_restlib.php');
}
}
$wpbookOptions = get_option('wpbookAdminOptions');
if (!empty($wpbookOptions)) {
foreach ($wpbookOptions as $key => $option)
$wpbookAdminOptions[$key] = $option;
}
$api_key = $wpbookAdminOptions['fb_api_key'];
$secret = $wpbookAdminOptions['fb_secret'];
$facebook = new Facebook($api_key, $secret);
$ProfileContent = 'Recent posts
'
. '
' . wpbook_profile_recent_posts(5) . '
';
// this call just updates the RefHandle, already set for the user profile
$facebook->api_client->call_method('facebook.Fbml.setRefHandle',
array('handle' => 'recent_posts',
'fbml' => $ProfileContent,
) );
}
add_filter('post_link','fb_filter_postlink',1,1);
add_action('admin_menu', 'wpbook_options_page');
// these capture new posts, not edits of previous posts
add_action('future_to_publish','wp_update_profile_boxes');
add_action('new_to_publish','wp_update_profile_boxes');
add_action('draft_to_publish','wp_update_profile_boxes');
?>