/*
Plugin Name: WP -> GF (PRO)
Plugin URI: http://gossamer-threads.com
Description: Publish your posts on GF.
Version: 1.0
Author: Gossamer Threads
Author URI: http://gossamer-threads.com
*/
// Constants
if ( !defined('WP2GF_DBSERVER') ) define('WP2GF_DBSERVER', 'localhost');
if ( !defined('WP2GF_DBNAME') ) define('WP2GF_DBNAME', 'mydb_gforum');
if ( !defined('WP2GF_DBUSERNAME') ) define('WP2GF_DBUSERNAME', 'gforum');
if ( !defined('WP2GF_DBPASSWORD') ) define('WP2GF_DBPASSWORD', 'gforum');
if ( !defined('WP2GF_DEFAULT_PUBLISHER_USERID') ) define('WP2GF_DEFAULT_PUBLISHER_USERID', 2);
if ( !defined('WP2GF_DEFAULT_PUBLISHER_USERNAME') ) define('WP2GF_DEFAULT_PUBLISHER_USERNAME', 'Publisher');
if ( !defined('WP2GF_INFOWARNING_USERINFOEMPTY') ) define('WP2GF_INFOWARNING_USERINFOEMPTY', 'User Info can not be empty, using default instead');
if ( !defined('WP2GF_DBWARNING_FORUMLIST') ) define('WP2GF_DBWARNING_FORUMLIST', 'Can not fetch the forum list');
if ( !defined('WP2GF_DBERROR_HANDLE') ) define('WP2GF_DBERROR_HANDLE', 'Can not connect to DB');
if ( !defined('WP2GF_DBERROR_UNIQUEID') ) define('WP2GF_DBERROR_UNIQUEID', 'Can not create unique id for the new post');
if ( !defined('WP2GF_DBERROR_INSERTPOST') ) define('WP2GF_DBERROR_INSERTPOST', 'Can not insert new post into the DB');
if ( !defined('WP2GF_DBERROR_INSERTEDID') ) define('WP2GF_DBERROR_INSERTEDID', 'Can not determine the ID of the new inserted post');
if ( !defined('WP2GF_DBERROR_UPDATEFORUM') ) define('WP2GF_DBERROR_UPDATEFORUM', 'Can not update the forum post counter');
if ( !defined('WP2GF_DBERROR_UPDATEFORUM') ) define('WP2GF_DBERROR_UPDATEUSERPOSTS', 'Can not update the user post counter');
if ( !defined('WP2GF_DBERROR_INTEGRITY') ) define('WP2GF_DBERROR_INTEGRITY', 'Can not delete the new post after failing to update the post counter');
/*
* FUNCTIONS
*/
function wp2gf_get_settings() {
$settings = unserialize(get_option('wp2gf_settings'));
if( !$settings ) {
$settings['publish'] = false;
$settings['forumid'] = 1;
$settings['userid'] = WP2GF_DEFAULT_PUBLISHER_USERID;
$settings['username'] = WP2GF_DEFAULT_PUBLISHER_USERNAME;
add_option('wp2gf_settings', serialize($settings));
}
return $settings;
}
function wp2gf_save_post_settings( $settings ) {
$settings['publish'] = $_POST['wp2gf_publish']?true:false;
$settings['forumid'] = $_POST['wp2gf_forumid'];
$settings['userid'] = ltrim($_POST['wp2gf_userid'])!=''?$_POST['wp2gf_userid']:WP2GF_DEFAULT_PUBLISHER_USERID;
$settings['username'] = ltrim($_POST['wp2gf_username'])!=''?$_POST['wp2gf_username']:WP2GF_DEFAULT_PUBLISHER_USERNAME;
if( ltrim($_POST['wp2gf_userid'])=='' || ltrim($_POST['wp2gf_username'])=='' )
$settings['warning'] = WP2GF_INFOWARNING_USERINFOEMPTY;
update_option('wp2gf_settings', serialize($settings));
}
// Adds a custom section to the "advanced" Post and Page edit screens
function wp2gf_add_custom_box() {
if( function_exists( 'add_meta_box' )) {
add_meta_box( 'wp2gf_sectionid', 'Publish on GForum', 'wp2gf_inner_custom_box', 'post', 'advanced' );
add_meta_box( 'wp2gf_sectionid', 'Publish on GForum', 'wp2gf_inner_custom_box', 'page', 'advanced' );
} else {
add_action( 'dbx_post_advanced', 'wp2gf_old_custom_box' );
add_action( 'dbx_page_advanced', 'wp2gf_old_custom_box' );
}
}
// Prints the inner fields for the custom post/page section
function wp2gf_inner_custom_box() {
global $wp2gf_settings, $wp2gf_forumlist;
// Use nonce for verification
echo '';
// The actual fields for data entry
echo '
';
echo 'Please note: It is your responsibility to provide the correct userid and username.';
}
// Prints the edit form for pre-WordPress 2.5 post/page
function wp2gf_old_custom_box() {
echo '
' . "\n";
echo '
\n";
}
function wp2gf_add_notices() {
global $wp2gf_settings;
if( $wp2gf_settings['error'] ) {
echo '
The following error occured while trying to connect to GForum: '.$wp2gf_settings['error'].'.