'http://s5.addthis.com/button0-fd.gif',
'width'=>83, 'height'=>16),
array('url'=>'http://s5.addthis.com/button0-rss.gif',
'width'=>83, 'height'=>16),
array('url'=>'http://s5.addthis.com/button1-fd.gif',
'width'=>125, 'height'=>16),
array('url'=>'http://s5.addthis.com/button1-rss.gif',
'width'=>125, 'height'=>16),
array('url'=>'http://s5.addthis.com/button2-fd.png',
'width'=>160, 'height'=>24),
array('url'=>'http://s5.addthis.com/button2-rssfeed.png',
'width'=>160, 'height'=>24));
// This is the function outputs the AddThis Subscribe button
function widget_at_subscribe($args, $buttons) {
// $args is an array of strings that help widgets to conform to
// the active theme: before_widget, before_title, after_widget,
// and after_title are the array keys. Default tags: li and h2.
extract($args);
$options = get_option('widget_at_subscribe');
$title = $options['title'];
$username = urlencode($options['username']);
$feedurl = urlencode($options['feedurl']);
$url = "http://www.addthis.com/feed.php?pub=$username&h1=$feedurl";
$javascript = $options['javascript'] ? "onclick=\"window.open('$url','addthis-subscribe','scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no'); return false;\"" : "";
$img = $buttons[$options['button']];
// These lines generate our output.
echo $before_widget;
if ($title)
echo $before_title . $title . $after_title;
echo '
';
echo $after_widget;
}
// This is the function that outputs the control form
function widget_at_subscribe_control($buttons) {
// Get our options and see if we're handling a form submission.
$options = get_option('widget_at_subscribe');
if ( !is_array($options) )
$options = array('title'=>'',
'username' => '',
'feedurl' => get_bloginfo('rss2_url'),
'button' => 2,
'javascript' => FALSE);
if ( $_POST['at-subscribe-submit'] ) {
// Remember to sanitize and format use input appropriately.
$options['title'] = strip_tags(stripslashes($_POST['at-subscribe-title']));
$options['username'] = $_POST['at-subscribe-username'];
$options['feedurl'] = $_POST['at-subscribe-feedurl'];
$options['button'] = $_POST['at-subscribe-button'];
$options['javascript'] = isset($_POST['at-subscribe-javascript']);
update_option('widget_at_subscribe', $options);
}
// Be sure you format your options to be valid HTML attributes.
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$username = htmlspecialchars($options['username'], ENT_QUOTES);
$feedurl = htmlspecialchars($options['feedurl'], ENT_QUOTES);
$button = $options['button'];
$javascript = $options['javascript'];
// Here is our little form segment. Notice that we don't need a
// complete form. This will be embedded into the existing form.
echo '';
echo '';
echo '';
echo '
';
echo '';
echo '';
}
// This registers our widget so it appears with the other available
// widgets and can be dragged and dropped into any active sidebars.
register_sidebar_widget('AddThis Subscribe', 'widget_at_subscribe', '', $buttons);
// This registers our optional widget control form.
register_widget_control('AddThis Subscribe', 'widget_at_subscribe_control', 280, 300, $buttons);
}
// Run our code later in case this loads prior to any required plugins.
add_action('widgets_init', 'widget_at_subscribe_init');
/*********************************************************************
* BOOKMARK WIDGET *
*********************************************************************/
// Put functions into one big function we'll call at the plugins_loaded
// action. This ensures that all required plugin functions are defined.
function widget_at_bookmark_init() {
// Check for the required plugin functions. This will prevent fatal
// errors occurring when you deactivate the dynamic-sidebar plugin.
if ( !function_exists('register_sidebar_widget') )
return;
$buttons = array(array('url'=>'http://s5.addthis.com/button0-bm.gif',
'width'=>83, 'height'=>16),
array('url'=>'http://s5.addthis.com/button1-bm.gif',
'width'=>125, 'height'=>16),
array('url'=>'http://s5.addthis.com/button2-bm.png',
'width'=>160, 'height'=>24));
// This is the function outputs the AddThis Social Bookmark button
function widget_at_bookmark($args, $buttons) {
// $args is an array of strings that help widgets to conform to
// the active theme: before_widget, before_title, after_widget,
// and after_title are the array keys. Default tags: li and h2.
extract($args);
$options = get_option('widget_at_bookmark');
if (is_single()) {
$linkurl = get_permalink();
$linktitle = single_post_title('',FALSE);
} else {
$parts = parse_url(get_option('siteurl'));
$linkurl = $parts['scheme'].'://'.$parts['host'].$_SERVER['REQUEST_URI'];
$linktitle = get_bloginfo('name') . wp_title('»',FALSE);
}
$linkurl = urlencode($linkurl);
$linktitle = urlencode($linktitle);
$title = $options['title'];
$username = urlencode($options['username']);
$url = "http://www.addthis.com/bookmark.php?pub=$username&url=$linkurl&title=$linktitle";
$javascript = $options['javascript'] ? "onclick=\"window.open('$url','addthis-bookmark','scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no'); return false;\"" : "";
$img = $buttons[$options['button']];
// These lines generate our output.
echo $before_widget;
if ($title)
echo $before_title . $title . $after_title;
echo '
';
echo $after_widget;
}
// This is the function that outputs the control form
function widget_at_bookmark_control($buttons) {
// Get our options and see if we're handling a form submission.
$options = get_option('widget_at_bookmark');
if ( !is_array($options) )
$options = array('title'=>'',
'username' => '',
'button' => 1,
'javascript' => FALSE);
if ( $_POST['at-bookmark-submit'] ) {
// Remember to sanitize and format use input appropriately.
$options['title'] = strip_tags(stripslashes($_POST['at-bookmark-title']));
$options['username'] = $_POST['at-bookmark-username'];
$options['button'] = $_POST['at-bookmark-button'];
$options['javascript'] = isset($_POST['at-bookmark-javascript']);
update_option('widget_at_bookmark', $options);
}
// Be sure you format your options to be valid HTML attributes.
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$username = htmlspecialchars($options['username'], ENT_QUOTES);
$button = $options['button'];
$javascript = $options['javascript'];
// Here is our little form segment. Notice that we don't need a
// complete form. This will be embedded into the existing form.
echo '';
echo '';
echo '
';
echo '';
echo '';
}
// This registers our widget so it appears with the other available
// widgets and can be dragged and dropped into any active sidebars.
register_sidebar_widget('AddThis Bookmark', 'widget_at_bookmark', '', $buttons);
// This registers our optional widget control form.
register_widget_control('AddThis Bookmark', 'widget_at_bookmark_control', 280, 200, $buttons);
}
// Run our code later in case this loads prior to any required plugins.
add_action('widgets_init', 'widget_at_bookmark_init');
?>