*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*/
require_once(ABSPATH . WPINC . '/functions.php');
require_once(ABSPATH . WPINC . '/widgets.php');
require_once(ABSPATH . WPINC . '/script-loader.php');
// wordpress registration /////////////////////////////////////////////
function defsem_widgets_register() {
$options = get_option('widget_defsem');
if (false === $options) {
$options = array(
twitter => array(user => 'p00ya', count => 3),
delicious => array(user => 'p00ya', count => 10),
lastfm => array(user => 'p00ya', count => 2));
add_option('widget_defsem', serialize($defsem_widgets_options), '', 'no');
} elseif (is_string($options)) {
$options = unserialize($options);
}
$GLOBALS['defsem_widgets_options'] = $options;
register_sidebar_widget('twitter', 'widget_twitter');
register_widget_control('twitter', 'widget_twitter_control');
register_sidebar_widget('del.icio.us', 'widget_delicious');
register_widget_control('del.icio.us', 'widget_delicious_control');
register_sidebar_widget('delicious tag', 'widget_delicious_tag');
register_widget_control('delicious tag', 'widget_delicious_control');
register_sidebar_widget('last.fm', 'widget_lastfm');
register_widget_control('last.fm', 'widget_lastfm_control');
add_action('wp_footer', 'defsem_widgets_footer');
wp_enqueue_script('defsem-widgets/common',
'/wp-content/plugins/defsem-widgets/common.min.js',
array('jquery'));
}
defsem_widgets_register();
function defsem_widgets_update_option() {
update_option('widget_defsem', serialize($GLOBALS['defsem_widgets_options']));
}
function defsem_widgets_control($service) {
$options =& $GLOBALS['defsem_widgets_options'][$service];
if (is_null($options))
$options = array();
$changed = false;
if (preg_match('/\s*([0-9]+)/', $_POST["widget_${service}_count"], $m)) {
$options['count'] = (int)$m[1];
$changed = true;
}
if (preg_match('/\s*([A-Za-z0-9]+)/', $_POST["widget_{$service}_user"], $m)) {
$options['user'] = $m[1];
$changed = true;
}
if ($_POST["widget_{$service}_proxy"]) {
$options['proxy'] = true;
$changed = true;
}
if ($changed)
defsem_widgets_update_option();
echo <<
END_HTML; if ('delicious' === $service) { echo <<