tutorial.
*/
class XPress_Menu_Widget extends WP_Widget
{
/**
* Declares the XPress_Menu_Widget class.
*
*/
function XPress_Menu_Widget(){
$widget_ops = array('classname' => 'widget_xpress', 'description' => __( "XPressME User Menu Widget") );
$control_ops = array('width' => 600, 'height' => 300);
$this->WP_Widget('XPress_Menu', __('XPressME MENU'), $widget_ops, $control_ops);
}
/**
* Displays the Widget
*
*/
function widget($args, $instance){
global $xpress_config,$xoops_config;
global $current_user;
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
# Before the widget
echo $before_widget;
# The title
if ( $title )
echo $before_title . $title . $after_title;
# Make the XPressME MENU widget
$menu = array();
for($i = 0; $i < 10; $i++) {
$menu[$i]['Type'] = $instance['Type_' . $i];
$menu[$i]['Title'] = $instance['Title_' . $i];
$menu[$i]['URL'] = $instance['URL_' . $i];
$menu[$i]['Visible'] = $instance['Visible_' . $i];
$menu[$i]['Weight'] = $instance['Weight_' . $i];
}
echo '
';
for($i = 0; $i < 10; $i++) {
$type = $menu[$i]['Type'];
if ($menu[$i]['Visible'] && !empty($menu[$i]['Title']) ){
switch($type){
case 0:
case 1:
echo '' . $menu[$i]['Title'] . ' ';
break;
case 2: // Add New
if (is_user_logged_in()){
if ($current_user->user_level > 0){
if (xpress_is_wp_version('<','2.1') ){
echo ''. $menu[$i]['Title'] .' ';
} else {
echo ''. $menu[$i]['Title'] .' ';
}
}
}
break;
case 3: // User Profile
if (is_user_logged_in()) {
echo ''. $menu[$i]['Title'] .' ';
}
break;
case 4: // WordPress Admin
if (is_user_logged_in()){
if ($current_user->user_level > 7){
echo ''. $menu[$i]['Title'] .' ';
}
}
break;
case 5: // Module Admin
if($GLOBALS["xoopsUserIsAdmin"]){
echo ''. $menu[$i]['Title'] .' ';
}
break;
case 6: // XPressME Setting
if (is_user_logged_in()){
if ($current_user->user_level > 7){
echo ''. $menu[$i]['Title'] .' ';
}
}
break;
case 7: // Display Mode Select
if ($xpress_config->viewer_type == 'user_select'){
echo disp_mode_set();
}
break;
default:
}
}
}
echo ' ';
# After the widget
echo $after_widget;
}
/**
* Saves the widgets settings.
*
*/
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
for($i = 0; $i < 10; $i++) {
$instance['Type_'. $i] = strip_tags(stripslashes($new_instance['Type_'. $i]));
$instance['Title_' . $i] = strip_tags(stripslashes($new_instance['Title_'. $i]));
if ($instance['Type_'. $i] < 2){
$instance['URL_' . $i] = strip_tags(stripslashes($new_instance['URL_'. $i]));
} else {
$instance['URL_' . $i] = '';
}
$instance['Visible_' . $i] = strip_tags(stripslashes($new_instance['Visible_'. $i]));
}
return $instance;
}
/**
* Creates the edit form for the widget.
*
*/
function form($instance){
global $xpress_config,$xoops_config;
if (xpress_is_wp_version('<','2.1') ){
$addnew = get_settings('siteurl').'/wp-admin/post.php';
} else {
$addnew = get_settings('siteurl').'/wp-admin/post-new.php';
}
$type = array();
$type[0] = __('Link', 'xpressme');
$type[1] = __('Site Home', 'xpressme');
$type[2] = __('Add New', 'xpressme');
$type[3] = __('User Profile', 'xpressme');
$type[4] = __('WordPress Admin', 'xpressme');
$type[5] = __('Module Admin', 'xpressme');
$type[6] = __('XPressME Setting', 'xpressme');
$type[7] = __('Display Mode Select', 'xpressme');
$auto_setting = __('Auto Setting', 'xpressme');
//Defaults
$instance = wp_parse_args( (array) $instance,
array(
'title'=> __('User Menu', 'xpressme'),
'Type_0' =>1 ,
'Title_0' => __('Site Home', 'xpressme'),
'URL_0' => get_xoops_url(),
'Visible_0' => 1,
'Type_1' =>2 ,
'Title_1' => __('Add New', 'xpressme'),
'URL_1' => $auto_setting,
'Visible_1' => 1,
'Type_2' =>3 ,
'Title_2' => __('User Profile', 'xpressme'),
'URL_2' => __('Auto Setting', 'xpressme'),
'Visible_2' => 1,
'Weight_2' => 3,
'Type_3' =>4 ,
'Title_3' => __('WordPress Admin', 'xpressme'),
'URL_3' => $auto_setting,
'Visible_3' => 1,
'Type_4' =>5 ,
'Title_4' => __('Module Admin', 'xpressme'),
'URL_4' => $auto_setting,
'Visible_4' => 1,
'Type_5' =>6 ,
'Title_5' => __('XPressME Setting', 'xpressme'),
'URL_5' => $auto_setting,
'Visible_5' => 1,
'Type_6' =>7 ,
'Title_6' => $auto_setting,
'URL_6' => $auto_setting,
'Visible_6' => 1,
'Type_7' =>0 ,
'Title_7' => __('Link', 'xpressme'),
'URL_7' => '',
'Visible_7' => 0,
'Type_8' =>0 ,
'Title_8' => __('Link', 'xpressme'),
'URL_8' => '',
'Visible_8' => 0,
'Type_9' =>0 ,
'Title_9' => __('Link', 'xpressme'),
'URL_9' => '',
'Visible_9' => 0,
) );
echo '
';
// Output the options
echo ''. "\n";
echo __('Title:') . '
'. "\n";
echo "
';
}
}// END class
/**
* Register Hello World widget.
*
* Calls 'widgets_init' action after the Hello World widget has been registered.
*/
function XPress_MenuInit() {
register_widget('XPress_Menu_Widget');
}
add_action('widgets_init', 'XPress_MenuInit');
?>