';
}
echo $after_widget;
}
function widget_assoc_dict_control() {
// Get our options and see if we're handling a form submission.
$options = get_option('widget_assoc_dict');
if ( !is_array($options) ) {
$options = array('title' => $assoc_dict_lang[$assoc_dict_lang_pref]["default_title"],
'startword' => '',
'language' => 'en',
'mail_address' => '',
'random' => '');
}
if ( $_POST['assocdict-submit'] ) {
$options['title'] = strip_tags(stripslashes($_POST['assocdict-title']));
$options['startword'] = strip_tags(stripslashes($_POST['assocdict-startword']));
$options['language'] = $_POST['assocdict-language'];
$options['mail_address'] = $_POST['assocdict-mail_address'];
$options['random'] = $_POST['assocdict-random'];
update_option('widget_assoc_dict', $options);
// does the db exist?
$testdb = $GLOBALS['wpdb']->get_row("show table status like 'widget_assoc_dict'");
if (!$testdb) {
$GLOBALS['wpdb']->query("CREATE TABLE `widget_assoc_dict` (`woordid` int(11) NOT NULL auto_increment,
`woord` varchar(255) NOT NULL default '',
`omschrijving` text NOT NULL,
`date_time` datetime NOT NULL default '0000-00-00 00:00:00',
`ip` varchar(255) NOT NULL default '',
`useragent` varchar(255) NOT NULL default '',
PRIMARY KEY (`woordid`),
KEY `wrd` (`woord`));");
}
}
// no need to display the 'random' option if there's less than 2 words in the db
$woord = $GLOBALS['wpdb']->get_row("SELECT count(woord) as aantal FROM widget_assoc_dict;");
$_showRandom = false;
if ($woord) {
if (intval($woord->aantal) > 1) {
$_showRandom = true;
}
}
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$_checked = "";
$_displaySW = "";
if ($_showRandom && ("1" == $options['random'])) {
$_checked = " selected";
$_displaySW = " display: none;";
}
$startword = htmlspecialchars($options['startword'], ENT_QUOTES);
$mail_address = $options['mail_address'];
if ('en' == $options['language']) {
$languageEN = ' selected';
$languageNL = '';
} else {
$languageEN = '';
$languageNL = ' selected';
}
?>
if ($_showRandom) {
?>
}
?>
}
// register widget
register_sidebar_widget('Associative dictionary', 'widget_assoc_dict');
// register widget control form
register_widget_control('Associative dictionary', 'widget_assoc_dict_control', 375, 190);
}
// Run our code later in case this loads prior to any required plugins.
add_action('plugins_loaded', 'widget_assoc_dict_init');
// let them know there's a new rss feed out there
add_action('wp_head', 'widget_assoc_dict_rss');
?>