<?php
/*
Plugin Name: Tarski links widget
Description: A better links widget for Tarski.
Author: Benedict Eastaugh and Chris Sternal-Johnson
Version: 1.2
Author URI: http://tarskitheme.com/
*/

// This gets called at the plugins_loaded action
function widget_tarski_links_init() {
    
    
// Check for the required API functions
    
if(!function_exists('register_sidebar_widget') || !function_exists('register_widget_control'))
        return;

    
// This saves options and prints the widget's config form.
    
function widget_tarski_links_control() {
    
    }

    
// This prints the widget
    
function widget_tarski_links($args) {
        if (
function_exists('wp_list_bookmarks')) {
            echo 
"<div class=\"bookmarks\">\n";    wp_list_bookmarks('category_before=&category_after=&title_before=<h3>&title_after=</h3>&show_images=0&show_description=0');
            echo 
"</div>\n";
        } else {
            global 
$wpdb;
        
            
extract($args);
            echo 
$before_widget;
            
$link_cats $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories");
            foreach(
$link_cats as $link_cat) {
                if(
get_links($link_cat->cat_id''''''FALSE''FALSEFALSE, -1FALSEFALSE) != '') {
                echo 
"        " $before_title $link_cat->cat_name $after_title "\n"?>
            <ul class="navlist" id="linkcat-<?php echo $link_cat->cat_id?>">
                <?php get_linksbyname($link_cat->cat_name'<li>''</li>'' 'false'name'falsefalse, -1false); ?>
            </ul><?php } } }
            echo 
$after_widget;
        }

    
// Tell Dynamic Sidebar about our new widget and its control
    
register_sidebar_widget('Tarski Links''widget_tarski_links');
    
// register_widget_control('Tarski Links', 'widget_tarski_links_control');
    
}

// Delay plugin execution to ensure Dynamic Sidebar has a chance to load first
add_action('plugins_loaded''widget_tarski_links_init');

?>