[Plugin: WPBook] Patch to allow publish as FB note
-
I have modified WPBook 2.0.13 to allow the user to select if he wants to publish the post as a note in FB instead as a single stream. Also I modified the cron to allow read comments from notes and streams.
Any suggestion would be wellcome.
************ The patch starts here ************
diff -urp wpbook/includes/publish_to_facebook.php wpbook_new/includes/publish_to_facebook.php
— wpbook/includes/publish_to_facebook.php 2011-02-21 11:22:30.000000000 -0500
+++ wpbook_new/includes/publish_to_facebook.php 2011-03-04 14:49:38.000000000 -0500
@@ -16,13 +16,14 @@ function wpbook_safe_publish_to_facebook$api_key = $wpbookAdminOptions[‘fb_api_key’];
$secret = $wpbookAdminOptions[‘fb_secret’];
– $target_admin = $wpbookAdminOptions[‘fb_admin_target’];
– $target_page = $wpbookAdminOptions[‘fb_page_target’];
– $stream_publish = $wpbookAdminOptions[‘stream_publish’];
– $stream_publish_pages = $wpbookAdminOptions[‘stream_publish_pages’];
– $wpbook_show_errors = $wpbookAdminOptions[‘show_errors’];
– $wpbook_promote_external = $wpbookAdminOptions[‘promote_external’];
– $wpbook_attribution_line = $wpbookAdminOptions[‘attribution_line’];
+ $as_note = $wpbookAdminOptions[‘fb_publish_as_note’];
+ $target_admin = $wpbookAdminOptions[‘fb_admin_target’];
+ $target_page = $wpbookAdminOptions[‘fb_page_target’];
+ $stream_publish = $wpbookAdminOptions[‘stream_publish’];
+ $stream_publish_pages = $wpbookAdminOptions[‘stream_publish_pages’];
+ $wpbook_show_errors = $wpbookAdminOptions[‘show_errors’];
+ $wpbook_promote_external = $wpbookAdminOptions[‘promote_external’];
+ $wpbook_attribution_line = $wpbookAdminOptions[‘attribution_line’];
$facebook = new Facebook($api_key, $secret);if((!empty($api_key)) && (!empty($secret)) && (!empty($target_admin)) && (($stream_publish == “true”) || $stream_publish_pages == “true”)) {
@@ -96,10 +97,16 @@ function wpbook_safe_publish_to_facebook
$action_links = json_encode($action_links);if($stream_publish == “true”) {
– $fb_response = ”;
– try{
– $fb_response = $facebook->api_client->stream_publish($message, $attachment, $action_links,$target_admin,$target_admin);
– } catch (Exception $e) {
+ $fb_response = ”;
+ try{
+ if($as_note == ‘on’) {
+ $allowedtags = array(‘img’=>array(‘src’=>array(), ‘style’=>array()), ‘span’=>array(‘id’=>array(), ‘style’=>array()), ‘a’=>array(‘href’=>array()), ‘p’=>array());
+ $content = wp_kses(stripslashes(apply_filters(‘the_content’,$my_post->post_content)),$allowedtags);
+ $fb_response = $facebook->api_client->notes_create($my_title, $content, $target_admin);
+ } else {
+ $fb_response = $facebook->api_client->stream_publish($message, $attachment, $action_links,$target_admin,$target_admin);
+ }
+ } catch (Exception $e) {
if($wpbook_show_errors) {
$wpbook_message = ‘Caught exception in stream publish for user: ‘ . $e->getMessage() .’Error code: ‘. $e->getCode();
wp_die($wpbook_message,’WPBook Error’);
diff -urp wpbook/includes/wpbook_cron.php wpbook_new/includes/wpbook_cron.php
— wpbook/includes/wpbook_cron.php 2011-02-21 11:22:30.000000000 -0500
+++ wpbook_new/includes/wpbook_cron.php 2011-03-04 14:54:28.000000000 -0500
@@ -149,7 +149,11 @@ function wpbook_import_comments() {
* So far both are inconsistent at best.
*/
if(WPBOOK_COMMENT_METHOD == ‘comment’) {
– $fbsql=”SELECT time,text,fromid,xid,post_id FROM comment WHERE post_id=’$mp->meta_value’ AND time > ‘$my_timestamp’ ORDER BY time ASC”;
+ $pos = strpos($mp->meta_value, ‘_’);
+ if ($pos === false)
+ $fbsql=”SELECT time,text,fromid,xid,post_id FROM comment WHERE object_id=’$mp->meta_value’ AND time > ‘$my_timestamp’ ORDER BY time ASC”;
+ else
+ $fbsql=”SELECT time,text,fromid,xid,post_id FROM comment WHERE post_id=’$mp->meta_value’ AND time > ‘$my_timestamp’ ORDER BY time ASC”;
if(DEBUG) {
$fp = fopen($debug_file, ‘a’);
$debug_string=date(“Y-m-d H:i:s”,time()).” : FBcomments, fbsql is $fbsql \n”;
diff -urp wpbook/wpbook.php wpbook_new/wpbook.php
— wpbook/wpbook.php 2011-02-21 11:22:30.000000000 -0500
+++ wpbook_new/wpbook.php 2011-03-04 15:01:20.000000000 -0500
@@ -106,7 +106,7 @@ function wpbook_getAdminOptions() {
}function setAdminOptions($wpbook_installation, $fb_api_key, $fb_secret,
– $fb_app_url,$fb_admin_target,$fb_page_target,$invite_friends,$require_email,
+ $fb_app_url,$fb_publish_as_note,$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,
@@ -125,6 +125,7 @@ function setAdminOptions($wpbook_install
‘fb_api_key’ => $fb_api_key,
‘fb_secret’ => $fb_secret,
‘fb_app_url’ => $fb_app_url,
+ ‘fb_publish_as_note’ => $fb_publish_as_note,
‘fb_admin_target’ => $fb_admin_target,
‘fb_page_target’ => $fb_page_target,
‘invite_friends’ => $invite_friends,
@@ -213,6 +214,7 @@ function wpbook_subpanel() {
$fb_api_key = $_POST[‘fb_api_key’];
$fb_secret = $_POST[‘fb_secret’];
$fb_app_url = $_POST[‘fb_app_url’];
+ $fb_publish_as_note = $_POST[‘fb_publish_as_note’];
$fb_admin_target = $_POST[‘fb_admin_target’];
$fb_page_target = $_POST[‘fb_page_target’];
$invite_friends = $_POST[‘invite_friends’];
@@ -277,7 +279,7 @@ function wpbook_subpanel() {
}
}
}
– setAdminOptions(1, $fb_api_key, $fb_secret, $fb_app_url,$fb_admin_target,$fb_page_target,
+ setAdminOptions(1, $fb_api_key, $fb_secret, $fb_app_url,$fb_publish_as_note,$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,
@@ -306,7 +308,7 @@ function wpbook_subpanel() {
//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”,
+ setAdminOptions(1, null,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,”[email protected]”,null,null,null,false);
}
@@ -382,6 +384,10 @@ function wpbook_subpanel() {
echo(“checked”);
}
echo ‘ id=”set_1″ > Publish new posts to YOUR Facebook Wall ‘;
+ echo ‘<p class=”wpbook_hidden wpbook_option_set_1 sub_options”>Publish as Notes: <input type=”checkbox” name=”fb_publish_as_note” ‘;
+ if($wpbookAdminOptions[‘fb_publish_as_note’] == ‘on’) echo ‘checked’;
+ echo ‘ >’;
+ echo ‘</p>’;
echo ‘<p class=”wpbook_hidden wpbook_option_set_1 sub_options”>YOUR Profile ID: <input type=”text” name=”fb_admin_target” value=”‘;
echo htmlentities($wpbookAdminOptions[‘fb_admin_target’]) .'” size=”15″ /> <span id=”grant_profile_permissions”></span>’;
/* this should be done by the Javascript now if that doesn’t work uncomment these lines
********** The patch ends here ********
- The topic ‘[Plugin: WPBook] Patch to allow publish as FB note’ is closed to new replies.