';
$out .= 'Get the Flash Player to see the slideshow.';
$out .= "\n\t".'';
echo $out;
}
/**********************************************************/
/* Slidehow widget control
/**********************************************************/
function widget_ngg_slideshow() {
// Check for the required plugin functions.
if ( !function_exists('register_sidebar_widget') )
return;
// Check for NextGEN Gallery
if ( !class_exists('nggallery') )
return;
function widget_show_ngg_slideshow($args) {
extract($args);
// Each widget can store its own options. We keep strings here.
$options = get_option('widget_nggslideshow');
// These lines generate our output.
echo $before_widget . $before_title . $options['title'] . $after_title;
nggSlideshowWidget($options['galleryid'] , $options['width'] , $options['height']);
echo $after_widget;
}
// Admin section
function widget_control_ngg_slideshow() {
global $wpdb;
$options = get_option('widget_nggslideshow');
if ( !is_array($options) )
$options = array('title'=>'Slideshow', 'galleryid'=>'0','height'=>'120','width'=>'160',);
if ( $_POST['ngg-submit'] ) {
$options['title'] = strip_tags(stripslashes($_POST['ngg-title']));
$options['galleryid'] = $_POST['ngg-galleryid'];
$options['height'] = $_POST['ngg-height'];
$options['width'] = $_POST['ngg-width'];
update_option('widget_nggslideshow', $options);
}
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$height = $options['height'];
$width = $options['width'];
// The Box content
echo '
';
echo '';
echo '
';
echo '';
echo '';
echo '';
}
register_sidebar_widget(array('NextGEN Slideshow', 'widgets'), 'widget_show_ngg_slideshow');
register_widget_control(array('NextGEN Slideshow', 'widgets'), 'widget_control_ngg_slideshow', 300, 200);
}
add_action('widgets_init', 'widget_ngg_slideshow');
/**
* nggWidget - The widget control for NextGEN Gallery ( require WP2.2 or hiogher)
*
* @package NextGEN Gallery
* @author Alex Rabe
* @copyright 2008
* @version 1.00
* @access public
*/
class nggWidget {
function nggWidget() {
// Run our code later in case this loads prior to any required plugins.
add_action('widgets_init', array(&$this, 'ngg_widget_register'));
}
function ngg_widget_register() {
if ( !class_exists('nggallery') )
return;
// For K2 Sidebar manager we do different
if(class_exists('K2SBM') && K2_USING_SBM ) {
K2SBM::register_sidebar_module('NextGEN Gallery', 'ngg_sbm_widget_output', 'sb-ngg-widget');
K2SBM::register_sidebar_module_control('NextGEN Gallery', 'ngg_sbm_widget_control');
} else {
// test for widget plugin > 2.2
if ( !function_exists('wp_register_sidebar_widget') )
return;
$options = get_option('ngg_widget');
$number = $options['number'];
if ( $number < 1 ) $number = 1;
if ( $number > 9 ) $number = 9;
$dims = array('width' => 410, 'height' => 300);
$class = array('classname' => 'ngg_widget');
for ($i = 1; $i <= 9; $i++) {
$name = sprintf(__('NextGEN Gallery %d','nggallery'), $i);
$id = "ngg-widget-$i"; // Never never never translate an id
wp_register_sidebar_widget($id, $name, $i <= $number ? array(&$this, 'ngg_widget_output') : /* unregister */ '', $class, $i);
wp_register_widget_control($id, $name, $i <= $number ? array(&$this, 'ngg_widget_control') : /* unregister */ '', $dims, $i);
}
add_action('sidebar_admin_setup', array(&$this, 'ngg_widget_admin_setup'));
add_action('sidebar_admin_page', array(&$this, 'ngg_widget_admin_page'));
}
}
function ngg_widget_admin_page() {
$options = get_option('ngg_widget');
?>
9 ) $number = 9;
if ( $number < 1 ) $number = 1;
$newoptions['number'] = $number;
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('ngg_widget', $options);
$this->ngg_widget_register($options['number']);
}
}
function ngg_widget_control($number, $is_K2_SMB = false) {
$options = $newoptions = get_option('ngg_widget');
// These post parameter are expected
$params = array('title','items','show','type','width','height','exclude','list');
// get the parameter from POST
if ( $_POST["ngg-submit-$number"] ) {
foreach ($params as $parameter) {
$value = trim(strip_tags(stripslashes($_POST["ngg-$parameter-$number"])));
// remove all non numeric values from the list
if ($parameter == 'list') {
$numeric_ids = array();
$ids = explode(',',$value);
if (is_array($ids)) {
foreach ($ids as $id) {
$id = trim($id);
if (is_numeric($id))
$numeric_ids[] = $id;
}
$value = implode(',', $numeric_ids);
}
}
$newoptions[$number][$parameter] = $value;
}
}
// save the parameter
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('ngg_widget', $options);
}
// Init parameters check
if (empty($options[$number]))
$options[$number] = array('title'=>'Gallery', 'items'=>4,'show'=>'thumbnail' ,'type'=>'random','width'=>75, 'height'=>50, 'exclude'=>'all');
foreach ($params as $parameter) {
$post[$parameter] = attribute_escape($options[$number][$parameter]);
}
// get the parameter from options -> POST
$items = (int) $options[$number]['items'];
if ( empty($items) || $items < 1 ) $items = 10;
// Here comes the form (Not for K2 Style)
if (!$is_K2_SMB) {
?>
get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE exclude != 1 ");
if ($count < $options[$number]['items'])
$options[$number]['items'] = $count;
$exclude_list = "";
// THX to Kay Germer for the idea & addon code
if ( (!empty($list)) && ($exclude != "all") ) {
$list = explode(',',$list);
// Prepare for SQL
$list = "'" . implode("', '", $list) . "'";
if ($exclude == "denied")
$exclude_list = "AND NOT galleryid IN ($list)";
if ($exclude == "allow")
$exclude_list = "AND galleryid IN ($list)";
}
if ( $options[$number]['type'] == "random" )
$imageList = $wpdb->get_results("SELECT * FROM $wpdb->nggpictures WHERE exclude != 1 $exclude_list ORDER by rand() limit $items");
else
$imageList = $wpdb->get_results("SELECT * FROM $wpdb->nggpictures WHERE exclude != 1 $exclude_list ORDER by pid DESC limit 0,$items");
echo $before_widget . $before_title . $options[$number]['title'] . $after_title;
echo "\n".''."\n";
echo $after_widget;
}
}
// let's show it
$nggWidget = new nggWidget;
/**
* ngg_sbm_widget_control()
* ONLY required for K2 Theme (tested with K2 RC4)
*
* @return return widget admin
*/
function ngg_sbm_widget_control() {
if ( !function_exists('checked') ) {
function checked( $checked, $current) {
if ( $checked == $current)
echo ' checked="checked"';
}
}
$number = 1;
// Check for Module id
if(isset($_POST['module_id']))
$number = $_POST['module_id'];
nggWidget::ngg_widget_control($number, true);
}
/**
* ngg_sbm_widget_output($args)
* ONLY required for K2 Theme
*
* @return widget content
*/
function ngg_sbm_widget_output($args) {
global $k2sbm_current_module;
$number = $k2sbm_current_module->id;
nggWidget::ngg_widget_output($args, $number , false);
}
/**
* nggDisplayRandomImages($number,$width,$height,$exclude,$list)
* Function for templates without widget support
*
* @return echo the widget content
*/
function nggDisplayRandomImages($number, $width = "75", $height = "50", $exclude = "all", $list = "") {
$options[1] = array('title'=>'',
'items'=>$number,
'show'=>'thumbnail' ,
'type'=>'random',
'width'=>$width,
'height'=>$height,
'exclude'=>'all',
'list'=>$list );
nggWidget::ngg_widget_output($args = array(), 1, $options);
}
/**
* nggDisplayRecentImages($number,$width,$height,$exclude,$list)
* Function for templates without widget support
*
* @return echo the widget content
*/
function nggDisplayRecentImages($number, $width = "75", $height = "50", $exclude = "all", $list = "") {
$options[1] = array('title'=>'',
'items'=>$number,
'show'=>'thumbnail' ,
'type'=>'recent',
'width'=>$width,
'height'=>$height,
'exclude'=>'all',
'list'=>$list );
nggWidget::ngg_widget_output($args = array(), 1, $options);
}
?>