prefix . "dragon_tweet";
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL,
ds_customtext text NOT NULL,
ds_customvia text NOT NULL,
ds_customrec text NOT NULL,
ds_customurl text NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
// Added some welcome data to ensure proper functionality.
$rows_affected = $wpdb->insert( $table_name, array( 'ds_customtext' => 'Welcome', 'id' => 0, 'ds_customvia' => 'DragonSearch', 'ds_customrec' => 'DragonSearch', 'ds_customurl' => ' ' ));
// Default some options if they have not been added already (previous installations)
$display_top = get_option('ds_display_top');
if(empty($display_top)) {
update_option('ds_display_top','on');
}
$display_bottom = get_option('ds_display_bottom');
if(empty($display_bottom)) {
update_option('ds_display_bottom','on');
}
$ds_counttype = get_option('ds_counttype');
if(empty($counttype)) {
update_option('ds_counttype','horizontal');
}
$ds_related = get_option('ds_related');
if(empty($ds_related )) {
update_option('ds_related','DragonSearch');
}
}
// Display a custom meta Edit Post
add_action( 'add_meta_boxes', 'dragon_social_box_add' );
function dragon_social_box_add() {
add_meta_box( 'dragon-social-box-id', 'DragonTweet - Customize Your Tweet', 'dragon_social_meta_box_cd', 'post', 'normal', 'high' );
}
function dragon_social_meta_box_cd( $post ) {
// Get the table data
global $wpdb;
global $post;
$table_name = $wpdb->prefix . "dragon_tweet";
$this_id = $post->ID;
$values = $wpdb->get_row( "SELECT * FROM $table_name WHERE id = $this_id" , ARRAY_A);
$customtext = $values['ds_customtext'];
$customvia = $values['ds_customvia'];
$customrec = $values['ds_customrec'];
$customurl = $values['ds_customurl'];
// Now display the meta box
wp_nonce_field( 'dragon_social_my_meta_box_nonce', 'dragon_social_meta_box_nonce' );
?>
Characters Left: Note: This does not include the URL characters or Via
For "via @JohnSmith", simply enter "JohnSmith". For no username or to fallback to the default (see Settings > Advanced Twitter to modify), simply leave it blank. You do not need to include the '@' symbol.
To Recommend a user to follow after the tweet, enter numerous usernames separated by commas. For no recommendation or to fallback to the default (see Settings > Advanced Twitter to modify), simply leave it blank. You do not need to include the '@' symbol.
array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
// Save the current data to the table
$table_name = $wpdb->prefix . 'dragon_tweet';
$id = $post->ID;
$ds_customtext = stripslashes($_POST['ds_customtext']);
$ds_customvia = stripslashes($_POST['ds_customvia']);
$ds_customrec = stripslashes($_POST['ds_customrec']);
$ds_customurl = stripslashes($_POST['ds_customurl']);
$found = $wpdb->update(
$table_name, //FROM table
array('ds_customtext' => $ds_customtext,
'ds_customvia' => $ds_customvia,
'ds_customrec' => $ds_customrec, // UPDATE data
'ds_customurl' => $ds_customurl
),
array('id' => $id) //WHERE id is this post id
);
if($found == false) {
$wpdb->insert(
$table_name, //FROM table
array('ds_customtext' => $ds_customtext,
'ds_customvia' => $ds_customvia,
'ds_customrec' => $ds_customrec,
'ds_customurl' => $ds_customurl, // INSERT data
'id' => $id)
);
}
}
// Displays a link to the options pane in the Settings submenu.
add_action('admin_menu', 'dragon_social_options');
function dragon_social_options() {
add_options_page("Advanced Twitter Settings", "Advanced Twitter", 'manage_options', "dragon-social-option", "dragon_social_display_options");
//call register settings function
add_action( 'admin_init', 'register_dragon_social_settings' );
}
function register_dragon_social_settings() {
//register our settings
register_setting( 'dragon-social-group', 'ds_display_top' );
register_setting( 'dragon-social-group', 'ds_display_bottom' );
register_setting( 'dragon-social-group', 'ds_large' );
register_setting( 'dragon-social-group', 'ds_via' );
register_setting( 'dragon-social-group', 'ds_related' );
register_setting( 'dragon-social-group', 'ds_counttype' );
}
// Displays the Options Pane
function dragon_social_display_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
?>
prefix . "dragon_tweet";
$this_id = $post->ID;
$values = $wpdb->get_row( "SELECT * FROM $table_name WHERE id = $this_id" , ARRAY_A);
// ...Set the custom meta data (first occurance only).
$ds_customtext = $values['ds_customtext'];
$ds_customrec = $values['ds_customrec'];
$ds_customvia = $values['ds_customvia'];
$ds_customurl = $values['ds_customurl'];
// If our current post's custom twitter description is empty...
if(empty($ds_customtext)){
// ...Rather than leave it blank, add the post's title.
$ds_customtext = $post->post_title;
}
$ds_customtext = htmlspecialchars($ds_customtext);
// If our customvia and default via are both empty, display nothing. If custom is empty, fallback on default.
if(empty($ds_customvia)){
$ds_via = get_option('ds_via');
if(!empty($ds_via)) {
$ds_customvia = $ds_via;
}
}
// This should not be an else because than the ds_via won't receive the same treatment.
if(!empty($ds_customvia)){
$ds_customvia = ' data-via="' . htmlspecialchars($ds_customvia) . '" ';
}
// If our customrecommendation and default related are both empty, display nothing. If custom is empty, fallback on default.
if(empty($ds_customrec)){
$ds_related = get_option('ds_related');
if(!empty($ds_related)) {
$ds_customrec = $ds_related;
}
}
// This should not be an else because than the ds_via won't receive the same treatment.
if(!empty($ds_customrec)) {
$ds_customrec = ' data-related ="' . htmlspecialchars($ds_customrec) . '" ';
}
if(empty($ds_customurl)){
if(!empty($ds_permalink)) {
$ds_customurl = $ds_permalink;
}
}
if(!empty($ds_customurl)) {
$ds_customurl = ' data-url ="' . htmlspecialchars($ds_customurl) . '" ';
}
// Only display a larger icon if it is not blank.
$ds_large = get_option('ds_large');
if(!empty($ds_large)) {
$ds_large = ' data-size="large" ';
}
// Only display count type if it is not blank.
$ds_counttype = get_option('ds_counttype');
if(!empty($ds_counttype)) {
// Special style to remove both the Tweet text and the counter
if($ds_counttype == "nocounterortweet") {
// ..which is dependant on the size of the tweet button
if(empty($ds_large)) {
$tweet_tag .= '';
}
else {
$tweet_tag .= '';
}
}
else {
$ds_counttype = ' data-count="' . $ds_counttype . '" ';
}
}
// Now let's merge our work together
// Create the base of the anchor
$tweet_tag .= '