1 | <?php
|
---|
2 | /*
|
---|
3 | * Plugin Name: XPressME MENU
|
---|
4 | * Version: 1.0
|
---|
5 | * Plugin URI: http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/
|
---|
6 | * Description: XPressME MENU widget using the the WordPress 2.8 widget API. This is meant strictly as a means of showing the new API using the <a href="http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/">tutorial</a>.
|
---|
7 | * Author: toemon
|
---|
8 | * Author URI: http://ja.xpressme.info
|
---|
9 | */
|
---|
10 | class XPress_Menu_Widget extends WP_Widget
|
---|
11 | {
|
---|
12 | /**
|
---|
13 | * Declares the XPress_Menu_Widget class.
|
---|
14 | *
|
---|
15 | */
|
---|
16 | function XPress_Menu_Widget(){
|
---|
17 | $widget_ops = array('classname' => 'widget_xpress', 'description' => __( "XPressME User Menu Widget") );
|
---|
18 | $control_ops = array('width' => 600, 'height' => 300);
|
---|
19 | $this->WP_Widget('XPress_Menu', __('XPressME MENU'), $widget_ops, $control_ops);
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Displays the Widget
|
---|
24 | *
|
---|
25 | */
|
---|
26 | function widget($args, $instance){
|
---|
27 | global $xpress_config,$xoops_config;
|
---|
28 | global $current_user;
|
---|
29 |
|
---|
30 | extract($args);
|
---|
31 | $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
|
---|
32 |
|
---|
33 | # Before the widget
|
---|
34 | echo $before_widget;
|
---|
35 |
|
---|
36 | # The title
|
---|
37 | if ( $title )
|
---|
38 | echo $before_title . $title . $after_title;
|
---|
39 |
|
---|
40 | # Make the XPressME MENU widget
|
---|
41 | $menu = array();
|
---|
42 | for($i = 0; $i < 10; $i++) {
|
---|
43 | $menu[$i]['Type'] = $instance['Type_' . $i];
|
---|
44 | $menu[$i]['Title'] = $instance['Title_' . $i];
|
---|
45 | $menu[$i]['URL'] = $instance['URL_' . $i];
|
---|
46 | $menu[$i]['Visible'] = $instance['Visible_' . $i];
|
---|
47 | $menu[$i]['Weight'] = $instance['Weight_' . $i];
|
---|
48 | }
|
---|
49 | echo '<ul>';
|
---|
50 | for($i = 0; $i < 10; $i++) {
|
---|
51 | $type = $menu[$i]['Type'];
|
---|
52 | if ($menu[$i]['Visible'] && !empty($menu[$i]['Title']) ){
|
---|
53 | switch($type){
|
---|
54 | case 0:
|
---|
55 | case 1:
|
---|
56 | echo '<li><a href="' . $menu[$i]['URL'] . '">' . $menu[$i]['Title'] . '</a></li>';
|
---|
57 | break;
|
---|
58 | case 2: // Add New
|
---|
59 | if (is_user_logged_in()){
|
---|
60 | if ($current_user->user_level > 0){
|
---|
61 | if (xpress_is_wp_version('<','2.1') ){
|
---|
62 | echo '<li><a href="'.get_settings('siteurl').'/wp-admin/post.php" title="'. $menu[$i]['Title'] .'">'. $menu[$i]['Title'] .'</a></li>';
|
---|
63 | } else {
|
---|
64 | echo '<li><a href="'.get_settings('siteurl').'/wp-admin/post-new.php" title="'. $menu[$i]['Title'] .'">'. $menu[$i]['Title'] .'</a></li>';
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | break;
|
---|
69 | case 3: // User Profile
|
---|
70 | if (is_user_logged_in()) {
|
---|
71 | echo '<li><a href="'.get_settings('siteurl').'/wp-admin/profile.php" title="' . $menu[$i]['Title'] .'">'. $menu[$i]['Title'] .'</a></li>';
|
---|
72 | }
|
---|
73 | break;
|
---|
74 | case 4: // WordPress Admin
|
---|
75 | if (is_user_logged_in()){
|
---|
76 | if ($current_user->user_level > 7){
|
---|
77 | echo '<li><a href="'.get_settings('siteurl').'/wp-admin/" title="'. $menu[$i]['Title'] .'">'. $menu[$i]['Title'] .'</a></li>';
|
---|
78 | }
|
---|
79 | }
|
---|
80 | break;
|
---|
81 | case 5: // Module Admin
|
---|
82 | if($GLOBALS["xoopsUserIsAdmin"]){
|
---|
83 | echo '<li><a href="'.get_settings('siteurl').'/admin/index.php" title="'. $menu[$i]['Title'] .'">'. $menu[$i]['Title'] .'</a></li>';
|
---|
84 | }
|
---|
85 | break;
|
---|
86 | case 6: // XPressME Setting
|
---|
87 | if (is_user_logged_in()){
|
---|
88 | if ($current_user->user_level > 7){
|
---|
89 | echo '<li><a href="'.get_settings('siteurl').'/wp-admin/admin.php?page=xpressme\\xpressme.php" title="'. $menu[$i]['Title'] .'">'. $menu[$i]['Title'] .'</a></li>';
|
---|
90 | }
|
---|
91 | }
|
---|
92 | break;
|
---|
93 | case 7: // Display Mode Select
|
---|
94 | if ($xpress_config->viewer_type == 'user_select'){
|
---|
95 | echo disp_mode_set();
|
---|
96 | }
|
---|
97 | break;
|
---|
98 | default:
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | echo '</ul>';
|
---|
104 | # After the widget
|
---|
105 | echo $after_widget;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Saves the widgets settings.
|
---|
110 | *
|
---|
111 | */
|
---|
112 | function update($new_instance, $old_instance){
|
---|
113 | $instance = $old_instance;
|
---|
114 | $instance['title'] = strip_tags(stripslashes($new_instance['title']));
|
---|
115 |
|
---|
116 | for($i = 0; $i < 10; $i++) {
|
---|
117 | $instance['Type_'. $i] = strip_tags(stripslashes($new_instance['Type_'. $i]));
|
---|
118 | $instance['Title_' . $i] = strip_tags(stripslashes($new_instance['Title_'. $i]));
|
---|
119 | if ($instance['Type_'. $i] < 2){
|
---|
120 | $instance['URL_' . $i] = strip_tags(stripslashes($new_instance['URL_'. $i]));
|
---|
121 | } else {
|
---|
122 | $instance['URL_' . $i] = '';
|
---|
123 | }
|
---|
124 | $instance['Visible_' . $i] = strip_tags(stripslashes($new_instance['Visible_'. $i]));
|
---|
125 | }
|
---|
126 |
|
---|
127 | return $instance;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Creates the edit form for the widget.
|
---|
132 | *
|
---|
133 | */
|
---|
134 | function form($instance){
|
---|
135 | global $xpress_config,$xoops_config;
|
---|
136 |
|
---|
137 | if (xpress_is_wp_version('<','2.1') ){
|
---|
138 | $addnew = get_settings('siteurl').'/wp-admin/post.php';
|
---|
139 | } else {
|
---|
140 | $addnew = get_settings('siteurl').'/wp-admin/post-new.php';
|
---|
141 | }
|
---|
142 | $type = array();
|
---|
143 | $type[0] = __('Link', 'xpressme');
|
---|
144 | $type[1] = __('Site Home', 'xpressme');
|
---|
145 | $type[2] = __('Add New', 'xpressme');
|
---|
146 | $type[3] = __('User Profile', 'xpressme');
|
---|
147 | $type[4] = __('WordPress Admin', 'xpressme');
|
---|
148 | $type[5] = __('Module Admin', 'xpressme');
|
---|
149 | $type[6] = __('XPressME Setting', 'xpressme');
|
---|
150 | $type[7] = __('Display Mode Select', 'xpressme');
|
---|
151 |
|
---|
152 | $auto_setting = __('Auto Setting', 'xpressme');
|
---|
153 |
|
---|
154 | //Defaults
|
---|
155 | $instance = wp_parse_args( (array) $instance,
|
---|
156 | array(
|
---|
157 | 'title'=> __('User Menu', 'xpressme'),
|
---|
158 |
|
---|
159 | 'Type_0' =>1 ,
|
---|
160 | 'Title_0' => __('Site Home', 'xpressme'),
|
---|
161 | 'URL_0' => get_xoops_url(),
|
---|
162 | 'Visible_0' => 1,
|
---|
163 |
|
---|
164 | 'Type_1' =>2 ,
|
---|
165 | 'Title_1' => __('Add New', 'xpressme'),
|
---|
166 | 'URL_1' => $auto_setting,
|
---|
167 | 'Visible_1' => 1,
|
---|
168 |
|
---|
169 | 'Type_2' =>3 ,
|
---|
170 | 'Title_2' => __('User Profile', 'xpressme'),
|
---|
171 | 'URL_2' => __('Auto Setting', 'xpressme'),
|
---|
172 | 'Visible_2' => 1,
|
---|
173 |
|
---|
174 | 'Weight_2' => 3,
|
---|
175 | 'Type_3' =>4 ,
|
---|
176 | 'Title_3' => __('WordPress Admin', 'xpressme'),
|
---|
177 | 'URL_3' => $auto_setting,
|
---|
178 | 'Visible_3' => 1,
|
---|
179 |
|
---|
180 | 'Type_4' =>5 ,
|
---|
181 | 'Title_4' => __('Module Admin', 'xpressme'),
|
---|
182 | 'URL_4' => $auto_setting,
|
---|
183 | 'Visible_4' => 1,
|
---|
184 |
|
---|
185 | 'Type_5' =>6 ,
|
---|
186 | 'Title_5' => __('XPressME Setting', 'xpressme'),
|
---|
187 | 'URL_5' => $auto_setting,
|
---|
188 | 'Visible_5' => 1,
|
---|
189 |
|
---|
190 | 'Type_6' =>7 ,
|
---|
191 | 'Title_6' => $auto_setting,
|
---|
192 | 'URL_6' => $auto_setting,
|
---|
193 | 'Visible_6' => 1,
|
---|
194 | 'Type_7' =>0 ,
|
---|
195 | 'Title_7' => __('Link', 'xpressme'),
|
---|
196 | 'URL_7' => '',
|
---|
197 | 'Visible_7' => 0,
|
---|
198 |
|
---|
199 | 'Type_8' =>0 ,
|
---|
200 | 'Title_8' => __('Link', 'xpressme'),
|
---|
201 | 'URL_8' => '',
|
---|
202 | 'Visible_8' => 0,
|
---|
203 |
|
---|
204 | 'Type_9' =>0 ,
|
---|
205 | 'Title_9' => __('Link', 'xpressme'),
|
---|
206 | 'URL_9' => '',
|
---|
207 | 'Visible_9' => 0,
|
---|
208 | ) );
|
---|
209 |
|
---|
210 | echo '
|
---|
211 | <script type="text/javascript">
|
---|
212 | function TypeSelect(type_id,title_id,url_id){
|
---|
213 | var type=document.getElementById(type_id);
|
---|
214 | var title=document.getElementById(title_id);
|
---|
215 | var link_url=document.getElementById(url_id);
|
---|
216 | var auto_set = \''. $auto_setting .'\';
|
---|
217 | title.value = type[type.value].text;
|
---|
218 | if(type.value > 1){
|
---|
219 | link_url.value = auto_set;
|
---|
220 | link_url.disabled = true;
|
---|
221 | link_url.style.backgroundColor = \'transparent\';
|
---|
222 | } else {
|
---|
223 | if (link_url.value == auto_set) link_url.value = \'\';
|
---|
224 | link_url.disabled = false;
|
---|
225 | link_url.style.backgroundColor = \'#FFFFEE\';
|
---|
226 | }
|
---|
227 | if(type.value == 1){
|
---|
228 | link_url.value = \''.get_xoops_url() . '\';
|
---|
229 | }
|
---|
230 | if(type.value == 7){
|
---|
231 | title.value = auto_set;
|
---|
232 | title.disabled = true;
|
---|
233 | title.style.backgroundColor = \'transparent\';
|
---|
234 | } else {
|
---|
235 | if (title.value == auto_set) title.value = \'\';
|
---|
236 | title.disabled = false;
|
---|
237 | title.style.backgroundColor = \'#FFFFEE\';
|
---|
238 | }
|
---|
239 |
|
---|
240 | }
|
---|
241 | </script>';
|
---|
242 |
|
---|
243 | // Output the options
|
---|
244 | echo '<p><label for="' . $this->get_field_name('title') . '">'. "\n";
|
---|
245 | echo __('Title:') . '<input style="width: 200px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $instance['title'] . '" /></label></p>'. "\n";
|
---|
246 | echo "
|
---|
247 | <table width='100%' class='outer' cellpadding='4' cellspacing='1' border=\"1\" bordercolor=\"#888888\">
|
---|
248 | <tr valign='middle' align='center' style=\"background-color:#2E323B;color:#FFFFFF\">
|
---|
249 | <th width='10%'>Type</th>
|
---|
250 | <th width='15%'>Title</th>
|
---|
251 | <th width='10%'>URL</th>
|
---|
252 | <th width='10px'>Visible</th>
|
---|
253 | </tr>
|
---|
254 | ";
|
---|
255 | for($i = 0; $i < 10; $i++) {
|
---|
256 | $even = $i % 2;
|
---|
257 | if ($even) {
|
---|
258 | $back_color = ' style="background-color:#E3E3E3"';
|
---|
259 | } else {
|
---|
260 | $back_color = ' style="background-color:#F5F5F5"';
|
---|
261 | }
|
---|
262 | $text_back_color = ' style="background-color:#FFFFEE"';
|
---|
263 | echo "<tr $back_color>";
|
---|
264 |
|
---|
265 | $select_arg = "'" . $this->get_field_id('Type_' . $i) . "','" . $this->get_field_id('Title_' . $i) . "','" . $this->get_field_id('URL_' . $i) . "'";
|
---|
266 | echo '<th><select id="' . $this->get_field_id('Type_' . $i) . '" name="' . $this->get_field_name('Type_' . $i) . '" ' .$back_color . 'onchange="TypeSelect(' . $select_arg . ')">';
|
---|
267 | for ($j = 0; $j < 8; $j++) {
|
---|
268 | if ($instance['Type_'. $i] == $j) $select = ' selected="selected"'; else $select = '';
|
---|
269 | echo '<option ' . $select . 'value="'. $j . '">' . $type[$j] . '</option>';
|
---|
270 | }
|
---|
271 | echo '</select></th>';
|
---|
272 |
|
---|
273 | if ($instance['Type_'. $i] == 7) {
|
---|
274 | $title_disible = 'disabled=disabled';
|
---|
275 | $title_back_color = $back_color;
|
---|
276 | $title_value = $auto_setting;
|
---|
277 |
|
---|
278 | } else {
|
---|
279 | $title_disible = '';
|
---|
280 | $title_back_color = $text_back_color;
|
---|
281 | $title_value = $instance['Title_'. $i];
|
---|
282 | }
|
---|
283 | echo '<th style="padding:2px"><input size="24" id="' . $this->get_field_id('Title_' . $i) . '" name="' . $this->get_field_name('Title_' . $i) . '" type="text" value="' . $title_value . '" ' .$title_back_color . $title_disible . '/></th>'. "\n";
|
---|
284 | if ($instance['Type_'. $i] > 1) {
|
---|
285 | $url_disible = 'disabled=disabled';
|
---|
286 | $url_back_color = $back_color;
|
---|
287 | $url_value = $auto_setting;
|
---|
288 | } else {
|
---|
289 | $url_disible = '';
|
---|
290 | $url_back_color = $text_back_color;
|
---|
291 | $url_value = $instance['URL_'. $i];
|
---|
292 | }
|
---|
293 | echo '<th style="padding:2px"><input size="40" id="' . $this->get_field_id('URL_' . $i) . '" name="' . $this->get_field_name('URL_' . $i) . '" type="text" value="' . $url_value . '" ' .$url_back_color . $url_disible . '/></th>'. "\n";
|
---|
294 | if ($instance['Visible_'. $i]) $check = ' checked="checked"'; else $check = '';
|
---|
295 | echo '<th><input size="4" id="' . $this->get_field_id('Visible_' . $i) . '" name="' . $this->get_field_name('Visible_' . $i) . '" type="checkbox" value="1"' . $check . ' /></th>'. "\n";
|
---|
296 | echo '</tr>';
|
---|
297 | }
|
---|
298 | echo '</table>';
|
---|
299 | }
|
---|
300 |
|
---|
301 | }// END class
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * Register Hello World widget.
|
---|
305 | *
|
---|
306 | * Calls 'widgets_init' action after the Hello World widget has been registered.
|
---|
307 | */
|
---|
308 | function XPress_MenuInit() {
|
---|
309 | register_widget('XPress_Menu_Widget');
|
---|
310 | }
|
---|
311 | add_action('widgets_init', 'XPress_MenuInit');
|
---|
312 | ?>
|
---|