-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuWidgets.php
218 lines (170 loc) · 6.75 KB
/
menuWidgets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Menu Widgets
* requires dynamic sidebars
* @author Andreas Pittrich
*
* These widgets are meant to ease the menu administration.
* A menu done with these widgets can be administrated through the admin interface by drag and drop.
* You can edit menu titles and entries or reorder them without modifying any code.
* Submenus can be added to an arbitary depth :)
*/
/**
* MenuEntryWidget Class
*/
class MenuEntryWidget extends WP_Widget {
function MenuEntryWidget() {
$widget_ops = array( 'classname' => 'menu_entry', 'description' => 'A link meant to be placed into a menu of some kind. Make sure to use "http://" or "https://" for external links.' );
parent::WP_Widget(false, $name = 'Menu Entry', $widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$url = apply_filters('widget_url', $instance['url']);
if(substr($url, 0, 4)!="http"){
$url=get_bloginfo('url')."/".$url;
}
echo $before_widget;
if($title){
echo "$before_title<a href=\"$url\">$title</a>$after_title";
}
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['url'] = strip_tags($new_instance['url']);
$instance['classname'] = 'blub';
return $instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
$url= esc_attr($instance['url']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label>
<label for="<?php echo $this->get_field_id('url'); ?>">
<?php _e('URL:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo $url; ?>" />
</label>
</p>
<?php
}
} // class MenuEntryWidget
/**
* SubmenuWidget Class
*/
class SubmenuWidget extends WP_Widget {
function SubmenuWidget() {
$widget_ops = array( 'classname' => 'submenu', 'description' => 'Adds a new sidebar used as a submenu. Reload the page for this to have an effect. If you remove a submenu with a subsubmenu, the subsubmenu becomes inactive and can thus be used somewhere else without loss of data. If you wish to remove the subsubmenu sidebar, remove the subsubmenu widget from the inactive widgets panel.' );
parent::WP_Widget(false, $name = 'Menu Submenu', $widget_ops);
$submenus=$this->get_settings();
foreach($submenus as $key => $submenu){
if (array_key_exists('title',$submenu)){
$class = $submenu['overlap'] ? 'overlap' : "";
register_sidebar(array(
'name' => 'Submenu: '.$submenu['title'],
'id' => 'submenu-'.$key,
'before_widget' => '<li id="%1$s" class="widget %2$s '.$class.'">',
'after_widget' => '</li>',
'before_title' => '',
'after_title' => '',
));
}
}
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$url = apply_filters('widget_title', $instance['url']);
echo $before_widget;
if( $title ){
echo "$before_title<a href=\"$url\">$title</a> $after_title";
echo "<ul $class>";
dynamic_sidebar('submenu-'.$this->number);
echo "</ul>";
}
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['url'] = strip_tags($new_instance['url']);
$instance['overlap'] = isset($new_instance['overlap']);
return $instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
$url= esc_attr($instance['url']);
$overlap = esc_attr($instance['overlap']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
<label for="<?php echo $this->get_field_id('url'); ?>"><?php _e('URL:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo $url; ?>" />
</p>
<p>
<input class="checkbox" type="checkbox" <?php checked(isset($instance['overlap']) ? $instance['overlap'] : 0); ?> id="<?php echo $this->get_field_id('overlap'); ?>" name="<?php echo $this->get_field_name('overlap'); ?>" />
<label for="<?php echo $this->get_field_id('overlap'); ?>"><?php _e('Overlapping submenus'); ?></label>
</p>
<?php
}
} // class SubmenuWidget
/**
* MenuFooterWidget Class
*/
class MenuFooterWidget extends WP_Widget {
function MenuFooterWidget() {
$widget_ops = array( 'classname' => 'menu_footer', 'description' => 'Add a footer to the menu.' );
parent::WP_Widget(false, $name = 'Menu Footer', $widget_ops);
}
function widget($args, $instance) {
extract( $args );
echo"
$before_widget
<div class=\"left\"></div>
<div class=\"center\"></div>
<div class=\"right\"></div>
$after_widget
";
}
function update($new_instance, $old_instance) {
return $instance;
}
function form($instance) {
echo "Nothing to configure.";
}
} // class MenuFooterWidget
/**
* MenuHeaderWidget Class
*/
class MenuHeaderWidget extends WP_Widget {
function MenuHeaderWidget() {
$widget_ops = array( 'classname' => 'menu_header', 'description' => 'Add a header to the menu.' );
parent::WP_Widget(false, $name = 'Menu Header', $widget_ops);
}
function widget($args, $instance) {
echo"
<li class=\"menu_header\">
<div class=\"left\"></div>
<div class=\"center\"></div>
<div class=\"right\"></div>
</li>
";
}
function update($new_instance, $old_instance) {
return $instance;
}
function form($instance) {
echo "Nothing to configure.";
}
} // class MenuHeaderWidget
add_action('widgets_init', create_function('', 'return register_widget("MenuEntryWidget");'));
add_action('widgets_init', create_function('', 'return register_widget("SubmenuWidget");'));
add_action('widgets_init', create_function('', 'return register_widget("MenuFooterWidget");'));
add_action('widgets_init', create_function('', 'return register_widget("MenuHeaderWidget");'));
?>