XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_widget_class.php @ 670

Last change on this file since 670 was 670, checked in by toemon, 13 years ago

プラグインリストにXPressME MENUが表示されるバグを修正 Fixes#382

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