Problems WIth Donkie Quotes Plugin & WordPress 2.1
-
Hi,
I recently upgraded to the WordPress 2.1.1 and then to 2.1.2 after the hacker unpleasantness and I’m having some trouble with my Donkie Quotes plugin and the two derivatives of the plugin that I created. When I attempt add a quote to my database using any of the random quote plugins, I get the following error:
Fatal error: Cannot redeclare db_assign_quote() (previously declared in /home/.papillon/***********/**********/blog/personal/wp-content/plugins/DumbBush.php:19) in /home/.papillon/***********/**********/blog/personal/wp-content/plugins/DumbBush.php on line 39
These are the same files that were working fine in WP 2.0.9 but for some reason WordPress 2.1 is vomiting on them. I’m relatively new to PHP but not at all dumb on the subject but I can’t find the cause of this error.
I’ve double checked the files and there is only one declared function called db_assign_quote so I don’t think that’s the problem.
I’ve double checked to make sure that there was only one php file in the plugin directory with the declared fuction (although if it had been a different file, the thrown error would have pointed to a different file).
I’m at a loss and must throw myself on the mercy of more experienced individuals.
Can anyone help?
Thanks a million for a great product and for all the effort.
-
Without actually seeing the content of the files in the plugin, there’s no way to tell what the problem is.
Thanks, Otto42, for the reply.
Here is the code from the file that’s throwing the error above. This isn’t the original Donkie Quote file but it was published under GNU so I modified the code to create multiple randomized quote generators. I actually have three and they are all throwing the same error message.
The interesting thing is I can get to every part of the plugin except writing the quotes. When I click on the save button after putting in the quote info, I get the above error.
*BEGIN INSERTED CODE*
<?php
/*
Plugin Name: Dumb Bush
Derived From: DokieQuote at
Plugin URI: https://dev.wp-plugins.org/wiki/DonkieQuote
Description: Displays a random quote by now (01.04.2006) presidnet George W. Bush. You must place thedb_do_random_quote();
template tag somwhere in you template to actually see the quote.
Author: Chris Shaffer
Version: 0.2
Author URI: https://kickthedonkey.net
*/$db_quote = false;
/*
this function is called during the wp_head action to setup the random quote
*/
function db_assign_quote()
{
global $wpdb;
$num_quotes = $wpdb->get_var(‘SELECT MAX(quote_id) FROM ‘ . get_option(‘db_table_nm’));
srand((double)microtime()*1000000);
$rand_quote = rand(1,$num_quotes);
$flag = false;
while( !$flag )
{
$db_quote = db_fetchQuote($rand_quote);
if($db_quote == false )
{
$flag = false;
//pull a new random number incase the other one was empty.
$rand_quote = rand(1,$num_quotes);
}
else
{
$flag = true;
}
}
return $db_quote;
}/*
template tag to display random quote.
*/
function db_do_random_quote($preTag='<div class=”db_quote”>’, $postTag = ‘</div>’ , $sepTag = ‘ -‘)
{
global $db_quote;if ($db_quote === false)
{
$db_quote = db_assign_quote();
}$output = $preTag;
$output .= $db_quote[‘text’];
$output .= $sepTag;
if(!empty($db_quote[‘src’]) && isset($db_quote[‘src’]) )
{
if(!empty($db_quote[‘src_url’]) && isset($db_quote[‘src_url’]) )
{
$output .= ‘‘;
}$output .= $db_quote[‘src’];
if(!empty($db_quote[‘src_url’]) && isset($db_quote[‘src_url’]) )
{
$output .= ‘‘;
}
}
else
{
$output .= ‘Unknown‘;
}$output .= $postTag;
print $output;
}// db_add_pages() is the sink function for the ‘admin_menu’ hook
function db_add_pages()
{
// Add a new menu under Manage:
add_management_page(‘Dumb Bush’, ‘Dumb Bush’, 5, __FILE__, ‘db_manage_page’);//Add subment to ‘write’ page:
add_submenu_page(‘post.php’, ‘Dumb Bush’, ‘Dumb Bush’, 5, __FILE__, ‘db_write_quote’);// Add a new menu under Options:
add_options_page(‘Dumb Bush’, ‘Dumb Bush’, 8, __FILE__, ‘db_options_page’);
}/*
Handles the ‘Write’ menu functionality for this plugin
*/
function db_write_quote()
{
global $wpdb, $user_ID;$quote_id = isset($_GET[‘quote’]) ? $_GET[‘quote’] : 0;
$messages[1] = __(‘Quote updated’);
//what am I doing?
if($_GET[‘action’] == ‘edit’)
{
if($quote_id < 1)
{
//no quote provided!
$error = true;
$displayForm = false;
$feedbackMsg = ‘You did not provide a Quote to edit! Perhaps you should look at the Manage Dumb Bush page?’;
}
else
{
//make sure the quote exists!
$db_quote = db_fetchQuote($quote_id);
$displayForm = true;
if($db_quote == false)
{
$error = true;
$displayForm = false;
$feedbackMsg = ‘Listen, I looked all over the database, but I just couldn\’t find the quote (ID \” . $quote_id . ‘\’) you were wanting to’
.’ edit. Maybe you should look at the Manage Dumb Bush page, and select one from that list?’;
}
//setup to display the edit form…
$form_action = ‘edit’;
$form_extra = “<input type=’hidden’ name=’quote_id’ value=’$quote_id’ />”;
}
}
elseif($_POST[‘action’] == ‘edit’)
{
//they’ve already seen the form… actually update the quote…
$form_action = ‘update’;
$quote_id = isset($_POST[‘quote_id’]) ? $_POST[‘quote_id’] : 0;$quotetxt = $_POST[‘quotetxt’];
$quote_source = $_POST[‘quote_source’];
$quote_source_url = $_POST[‘quote_source_url’];$displayForm = false;
if(strlen($quotetxt) < 1)
{
$error = true;
$displayForm = true;
$feedbackMsg = ‘Looks like you didn\’t fill in the Quote field. Care to try again?’;
$db_quote[‘text’] = $quotetxt;
$db_quote[‘src’] = $quote_source;
$db_quote[‘src_url’] = $quote_source_url;
$form_action = ‘edit’;
$form_extra = “<input type=’hidden’ name=’quote_id’ value=’$quote_id’ />”;
}
elseif($quote_id < 1)
{
$error = true;
$displayForm = false;
$feedbackMsg = ‘You did not provide a Quote to edit! Perhaps you should look at the Manage Dumb Bush page?’;
}
else
{
//they’ve made it this far. Write the quote to the database.
$quote_source = strlen($quote_source) < 1 ? ‘NULL’ : ‘\” . $quote_source . ‘\”;
$quote_source_url = strlen($quote_source_url) < 1 ? ‘NULL’ : ‘\” . $quote_source_url . ‘\”;
$quotetxt = apply_filters(‘content_save_pre’, $quotetxt);
$quotetxt = ‘\” . $quotetxt . ‘\”;
$query = “UPDATE ” . get_option(‘db_table_nm’) . ” SET quote_text = $quotetxt, quote_src = $quote_source, quote_src_url = $quote_source_url WHERE quote_id = $quote_id”;
//execute query, and see what happened:
$wpdb->query($query);
$error = false;
$displayForm = false;
$feedbackMsg = “Quote ‘$quote_id’ successfully updated!</p><p>Manage Dumb Bush<br/>Create New Quote“;
}
}
elseif($_POST[‘action’] == ‘new’)
{
//They’ve filled in the form for a new quote. Add it.
$form_action = ‘writenew’;
$quote_source = strlen($_POST[‘quote_source’]) < 1 ? ‘NULL’ : ‘\” . $_POST[‘quote_source’] . ‘\”;
$quote_source_url = strlen($_POST[‘quote_source_url’]) < 1 ? ‘NULL’ : ‘\” . $_POST[‘quote_source_url’] . ‘\”;
$displayForm = false;if(strlen($quotetxt) < 1)
{
$error = true;
$displayForm = true;
$feedbackMsg = ‘Looks like you didn\’t fill in the Quote field. Care to try again?’;
$db_quote[‘src’] = $quote_source;
$db_quote[‘text’] = $quotetxt;
$db_quote[‘src_url’] = $quote_source_url;
$form_action = ‘new’;
}
$quotetxt = apply_filters(‘content_save_pre’, $_POST[‘quotetxt’]);
$quotetxt = ‘\” . $quotetxt . ‘\”;
$id_result = $wpdb->get_row(“SHOW TABLE STATUS LIKE ‘” . get_option(‘db_table_nm’) . “‘”);
$quote_id = $id_result->Auto_increment;
$query = “INSERT INTO ” . get_option(‘db_table_nm’) . ” VALUES($quote_id,$user_ID,$quotetxt,$quote_source, $quote_source_url, NOW())”;
//execute query, and see what happened:
$wpdb->query($query);
$error = false;
$displayForm = false;
$feedbackMsg = “Quote successfully added as ID ‘$quote_id’!</p><p>Manage Dumb Bush<br/>Create New Quote“;
$form_action = ‘new’;
$displayForm = true;
$db_quote = false;
}
else
{
//display write new quote form.
$form_action = ‘new’;
$displayForm = true;
}?>
<?php if (isset($feedbackMsg)) : ?>
<div class=”updated”><p><?php if($error) { echo ‘ERROR: ‘; } echo $feedbackMsg; ?></p></div>
<?php endif; ?><?php if ($displayForm) : ?>
<form name=”quote” action=”post.php?page=DumbBush.php” method=”post” id=”quote”>
<div class=”wrap”>
<h2><?php _e(‘Write Quote’); ?></h2>
<p><?php _e(get_option(‘db_quote_desc’)); ?></p><input type=”hidden” name=”user_ID” value=”<?php echo $user_ID ?>” />
<input type=”hidden” name=”action” value=”<?php echo $form_action ?>” />
<?php echo $form_extra; ?><?php if (isset($_GET[‘message’]) && 1 > $_GET[‘message’]) : ?>
<script type=”text/javascript”>
<!–
function focusit() {
// focus on first input field
document.quote.title.focus();
}
window.onload = focusit;
//–>
</script>
<?php endif; ?>
<div id=”quotestuff”>
<fieldset id=”quotetxtdiv”>
<div>
<p>Quote</p>
<textarea name=”quotetxt” rows=”10″ cols=”60″ name=”excerpt” tabindex=”1″ id=”quotetxt”><?php echo $db_quote[‘text’] ?></textarea>
</div>
</fieldset>
<br/>
<fieldset id=”quotesrcdiv”>
<div>
<p>Quote Source</p>
<p>Who said this quote (if you don’t know, leave blank).</p>
<input type=”text” name=”quote_source” size=”60″ tabindex=”2″ value=”<?php echo $db_quote[‘src’]; ?>” id=”quotesrc” />
</div>
</fieldset><fieldset id=”quotesrcurldiv”>
<div>
<p>Quote Source URL</p>
<p>Where you found this quote (if you don’t know, leave blank).</p>
<input type=”text” name=”quote_source_url” size=”60″ tabindex=”3″ value=”<?php echo $db_quote[‘src_url’]; ?>” id=”quotesrcurl” />
</div>
</fieldset><?php
?>
<script type=”text/javascript”>
<!–
edCanvas = document.getElementById(‘content’);
//–>
</script><p class=”submit”>
<input type=”submit” name=”submit” value=”<?php _e(‘Save’) ?>” style=”font-weight: bold;” tabindex=”6″ />
</p></div>
<h3><?php _e(‘Manage Dumb Bush’); ?> »</h3>
</div>
</form>
<?php endif; ?>
<?php
}// db_manage_page() displays the page content for the Manage->Quote submenu
function db_manage_page()
{
global $wpdb, $db_table_nm, $user_ID, $user_level;if($_GET[‘action’] == ‘delete’)
{
if(isset($_GET[‘quote’]))
{
//delete the puppy!
$result = $wpdb->query(“DELETE FROM ” . get_option(‘db_table_nm’) . ” WHERE quote_id = ” . $_GET[‘quote’]);
//check to see what happened…
if($result)
{
$error = false;
$feedbackMsg = ‘Quote \”. $_GET[‘quote’] . ‘\’ successfully removed! You deserve a cookie.’;
}
else
{
$error = true;
$feedbackMsg = ‘Listen, I looked all over the database, but I just couldn\’t find the quote (ID \” . $_GET[‘quote’] . ‘\’) you where wanting to’
.’ delete. Sorry. Its probably my fault. However, just select another quote from the list below ‘
. ‘if you\’re still in a deleting mood.’;
}
}
else
{
$error = true;
$feedbackMsg = ‘You did not provide a Quote to delete! Perhaps you should look at the Manage Dumb Bush page?’;
}
}?>
<?php if (isset($feedbackMsg)) : ?>
<div class=”updated”><p><?php if($error) { echo ‘ERROR: ‘; } echo $feedbackMsg; ?></p></div>
<?php endif; ?><div class=”wrap”>
<h2><?php _e(‘Quote Management’); ?></h2>
<?php$query = “SELECT quote_id, user_login, quote_text, quote_src, quote_src_url, quote_added FROM ” . get_option(‘db_table_nm’) . “, $wpdb->users WHERE dumb_bush.quote_author = $wpdb->users.ID ORDER BY quote_id DESC”;
if (isset($user_ID) && (” != intval($user_ID))) {
$quotes = $wpdb->get_results($query);
} else {
$quotes = $wpdb->get_results($query);
}if ($quotes)
{
?>
<table width=”100%” cellpadding=”3″ cellspacing=”3″>
<tr>
<th scope=”col”><?php _e(‘ID’) ?></th>
<th scope=”col”><?php _e(‘Quote Text’) ?></th>
<th scope=”col”><?php _e(‘Source’) ?></th>
<th scope=”col”><?php _e(‘Owner’) ?></th>
<th scope=”col”><?php _e(‘Added’) ?></th>
<th scope=”col”></th>
<th scope=”col”></th>
</tr><?php
db_quote_rows($quotes);
?>
</table>
<?php
}
else
{
?>
<p><?php _e(‘No quotes yet.’) ?></p>
<?php
} // end if ($quotes)
?>
<p><?php _e(get_option(‘db_quote_desc’)); ?></p>
<h3><?php _e(‘Create New Quote’); ?> »</h3>
</div>
<?php
}/*
Options->Quotes submenu handler.
*/
function db_options_page() {
global $wpdb;if($_POST[‘action’] == ‘update’)
{
//update the data.
//check the data.
$error = false;$quote_table = $_POST[‘quote_table’];
$quote_preview_len = $_POST[‘quote_preview_len’];
$quote_desc = $_POST[‘quote_desc’];if(strlen($quote_table) < 1)
{
$errorMsg .= ‘You must fill in the \’Quote Table\’ field!<br/>’;
$error = true;
}
if(!is_numeric($quote_preview_len))
{
$errorMsg .= ‘You must provide an integer in the \’Preview Length\’ field!<br/>’;
$error = true;
}$displayForm = true;
if($error)
{
$feedbackMsg = “$errorMsg</p>Please correct the above errors and re-submit the form.”;
}
else
{
$feedbackMsg = “Options Updated!”;
update_option(‘db_table_nm’, $quote_table);
update_option(‘db_previewTextLength’, $quote_preview_len);
update_option(‘db_quote_desc’, $quote_desc);
}}
else
{
$displayForm = true;
$quote_table = get_option(‘db_table_nm’);
$quote_preview_len = get_option(‘db_previewTextLength’);
$quote_desc = get_option(‘db_quote_desc’);
}if($displayForm)
{
$res = $wpdb->get_results(‘SELECT option_name, option_description FROM ‘ . $wpdb->options . ‘ WHERE option_name = \’db_table_nm\’ OR option_name = \’db_previewTextLength\’ OR option_name = \’db_quote_desc\”);if($res)
{
//there should only be one quote here…
foreach($res as $option)
{
$opt_desc[$option->option_name] = $option->option_description;
}
}
}?>
<div class=”wrap”>
<h2><?php _e(‘Quote Options’) ?></h2>
<?php if (isset($feedbackMsg)) : ?>
<div class=”updated”><p><?php if($error) { echo ‘ERROR: ‘; } echo $feedbackMsg; ?></p></div>
<?php endif; ?>
<?php if ($displayForm) : ?>
<form name=”quoteoptions” method=”post” action=”options-general.php?page=DumbBush.php”>
<input type=”hidden” name=”action” value=”update” />
<!–<input type=”hidden” name=”page_options” value=”‘hack_file’,’use_fileupload’,’fileupload_realpath’,’fileupload_url’,’fileupload_allowedtypes’,’fileupload_maxk’,’fileupload_maxk’,’fileupload_minlevel’,’use_geo_positions’,’use_linksupdate'” /> –>
<!–<fieldset class=”options”>
<legend>
<input name=”use_fileupload” type=”checkbox” id=”use_fileupload” value=”1″ <?php checked(‘1’, get_settings(‘use_fileupload’)); ?> />
<label for=”use_fileupload”><?php _e(‘Allow File Uploads’) ?></label></legend>–>
<table width=”100%” cellspacing=”2″ cellpadding=”5″ class=”editform”>
<tr>
<th width=”33%” valign=”top” scope=”row”><?php _e(‘Quote Table:’) ?> </th>
<td>
<input name=”quote_table” type=”text” id=”quote_table” value=”<?php echo $quote_table; ?>” size=”50″ />
<?php echo $opt_desc[‘db_table_nm’] ?>
</td>
</tr>
<tr>
<th valign=”top” scope=”row”><?php _e(‘Preview Length:’) ?> </th>
<td>
<input name=”quote_preview_len” type=”text” id=”quote_preview_len” value=”<?php echo $quote_preview_len; ?>” size=”5″ />
<?php echo $opt_desc[‘db_previewTextLength’] ?>
</td>
</tr>
<tr>
<th width=”33%” valign=”top” scope=”row”><?php _e(‘Quote Description:’) ?> </th>
<td>
<input name=”quote_desc” type=”text” id=”quote_desc” value=”<?php echo $quote_desc; ?>” size=”50″ />
<?php echo $opt_desc[‘db_quote_desc’] ?>
</td>
</tr>
</table>
<!–</fieldset>–>
<p class=”submit”>
<input type=”submit” name=”Submit” value=”<?php _e(‘Update Options’) ?> »” />
</p>
</form>
<?php endif; ?>
</div>
<?php
}/*
Spits out all the quotes in a nice little table for the Manage->Quotes submenu.
*/
function db_quote_rows( $quotes)
{
global $wpdb, $class, $user_level;foreach($quotes as $quote)
{
$class = (‘alternate’ == $class) ? ” : ‘alternate’;
?>
<tr class='<?php echo $class; ?>’>
<th scope=”row”><?php echo $quote->quote_id; ?></th>
<td>
<?php print db_previewText($quote->quote_text); ?>
</td>
<td>
<?php print $quote->quote_src; ?>
</td>
<td><?php echo $quote->user_login; ?></td>
<td><?php echo mysql2date(‘Y-m-d g:i a’, $quote->quote_added); ?></td>
<td><?php if (($user_level >= $quote->user_level) or ($user_login == $quote->user_login)) { echo “quote_id’ class=’edit’>” . __(‘Edit’) . ““; } ?></td>
<td><?php if (($user_level >= $quote->user_level) or ($user_login == $quote->user_login)) { echo “quote_id’ class=’delete’ onclick=\”return confirm(‘” . sprintf(__(“You are about to delete this quote \’%s\’\\n \’OK\’ to delete, \’Cancel\’ to stop.”), $quote->quote_id) . “‘)\”>” . __(‘Delete’) . ““; } ?></td>
</tr><?php
}}
/*
Generates a ‘preview’ of the quote for display in the Manage->Quotes table.
*/
function db_previewText($text)
{
// Change to the number of characters you want to display
$chars = get_option(‘db_previewTextLength’);$text = $text.” “;
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,’ ‘));
$text = $text.”…”;return $text;
}/*
Fetches a single quote, by ID.
*/
function db_fetchQuote( $quote_id )
{
global $wpdb;
//make sure the quote exists!
$res = $wpdb->get_results(‘SELECT quote_text, quote_src, quote_src_url FROM ‘ . get_option(‘db_table_nm’) . ‘ WHERE quote_id = ‘ . $quote_id);if($res)
{
//there should only be one quote here…
foreach($res as $quote)
{
$db_quote[‘text’] = $quote->quote_text;
$db_quote[‘src’] = $quote->quote_src;
$db_quote[‘src_url’] = $quote->quote_src_url;
}/*print “
"; print_r($db_quote); print "
“;
exit();*/return $db_quote;
}
else
{
return false;
}
}// Synch up with the rest of WordPress.
add_action ( ‘wp_head’, ‘db_assign_quote’, 10 );add_action(‘admin_menu’, ‘db_add_pages’);
//build default options, if they don’t exist.
add_option(‘db_table_nm’, ‘dumb_bush’, ‘Table where the quotes are stored.’);add_option(‘db_previewTextLength’,’45’, ‘How much of the quote should be previewed on the Manage Dumb Bush page.’);
add_option(‘db_quote_desc’, ‘Quotes are interesting, insiteful, of funny phrases that you may find add value to display on your blog.’, ‘Describes what quotes are.’);
?>Oops, sorry, I guess it ‘is available under the BPL (Beer Public Licence)’; from the Wiki site but it still says the code is free to use.
I really would have preferred a link to the code in question. Posting it here just messes up the formatting and makes it rather a waste of time.
I actually have three and they are all throwing the same error message.
Ah. Well, there’s your problem. You are duplicating functions. Why? Because you have three of each one.
The fact that they are in separate plugins makes no difference. You cannot have the same function name in the entire system, not just in plugins.
Remove two of these duped plugins of yours.
Actually, that isn’t the problem; if it were, the error message would be throwing a duplicate pointing to a different file. This is pointing to the same file on a different line. The three files I mention have different functions defined: db_assign_quote, dq_assign_quote and ip_assign_quote.
I’m pretty sure it’s a bug in WordPress 2.1 as these exact same files work fine in 2.0.x; I just tested it again. I’m in the process of placing the code on my server so you can see it formatted. I’ll edit the previous post with a link when it is up.
Ah, crud. I didn’t realize I couldn’t edit the posts previous to the last: Here’s the link.
I’m pretty sure it’s a bug in WordPress 2.1
Can’t be. WordPress 2.1 is no different than WordPress 2.0 with respect to plugins. It just include’s them. That’s it.
If PHP is giving you an error, then it’s because it doesn’t like your PHP for whatever reason. Or perhaps the admin menus changed enough to break the way your code is trying to do things now. Dunno. Whatever it is, it’s not a bug in WordPress, it’s a bug in the plugin.
You could do something along these lines to prevent accidental redefintions…
if ( !function_exists('db_assign_quote') ) : function db_assign_quote(){ ... } endif;
Thanks, that makes sense. Like I said, I’m not unfamiliar, per se, but not an expert by stretch, twist or turn of the truth.
I’ll give your code a try and see what happens. I’ll report back with the reults.
OK, that worked, but now It’s not properly displaying when the quote is added to the database. It should be displaying a message indicating the quote ID and a new entry form for antoher quote. I’ll have to play with it to see if I can figure out the issue.
I don’t know what to tell you. My best guess is that you’re missing some closing brackets somewhere or something like that. Sorry.
OK, I’ve looked at the code and if I put the if statements in there; I don’t get the error, but nothing is written to the database during the create new quote and the edit functionality pulls up a blank screen. Any other ideas what might be happening?
Dunno. Maybe the links changed. A lot of stuff in the wp-admin changed, you might start looking at that.
I’m still crawling the net trying to find this and apparently this isn’t the only plugin having this type of difficulties. I’ll keep looking.
FYI, for future reference, I did some compares against the admin and plugin files in the wp-admin directory and wordpress is actually handling it’s plugins very differently between 2.0.9 and 2.1.2.
I’ll report back when I solve the problem and if anyone else has any suggestions, please post them here.
Thanks again for all the help and hard work, WP is still hands down the best blog software out there.
I gave up and reverted back to 2.0.9. Seems like a lot of things work better in that version than in 2.1.x so I’ll stick with it; it’s supported through 2010.
I’m going to leave this open in the hopes that someone might be able to help resolve the issue.
- The topic ‘Problems WIth Donkie Quotes Plugin & WordPress 2.1’ is closed to new replies.