XPressME Integration Kit

Trac


Ignore:
Timestamp:
Nov 19, 2009, 8:49:32 PM (14 years ago)
Author:
toemon
Message:

ユーザメニュー用のウィジェット追加 Fixes #220

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme_widget_class.php

    r403 r445  
    1616        function XPress_Menu_Widget(){ 
    1717                $widget_ops = array('classname' => 'widget_xpress', 'description' => __( "XPressME User Menu Widget") ); 
    18                 $control_ops = array('width' => 400, 'height' => 300); 
     18                $control_ops = array('width' => 600, 'height' => 300); 
    1919                $this->WP_Widget('XPress_Menu', __('XPressME MENU'), $widget_ops, $control_ops); 
    2020        } 
     
    2626        function widget($args, $instance){ 
    2727                global $xpress_config,$xoops_config; 
     28                global $current_user; 
    2829 
    2930                extract($args); 
     
    3839 
    3940                # 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                }                        
    4049                echo '<ul>'; 
    4150                for($i = 0; $i < 10; $i++) { 
    42                         $link_name = $instance['name' . $i]; 
    43                         $link_url = $instance['link' . $i]; 
    44                         if (!empty($link_name)) echo '<li><a href="' . $link_url . '">' . $link_name . '</a></li>'; 
     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                        } 
    45101                } 
     102 
    46103                echo '</ul>'; 
    47104                # After the widget 
     
    58115                 
    59116                for($i = 0; $i < 10; $i++) { 
    60                         $instance['name'. $i] = strip_tags(stripslashes($new_instance['name'. $i])); 
    61                         $instance['link' . $i] = strip_tags(stripslashes($new_instance['link'. $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])); 
    62125                } 
    63126 
     
    71134        function form($instance){ 
    72135                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                 
    73154                //Defaults 
    74155                $instance = wp_parse_args( (array) $instance,  
    75156                array( 
    76                         'title'=> __('User Menu'), 
    77                         'name0' => __('Site Home'), 
    78                         'link0' => $xoops_config->xoops_url, 
    79                         'name1' => '', 
    80                         'link1' => '', 
    81                         'name2' => '', 
    82                         'link2' => '', 
    83                         'name3' => '', 
    84                         'link3' => '', 
    85                         'name4' => '', 
    86                         'link4' => '', 
    87                         'name5' => '', 
    88                         'link5' => '', 
    89                         'name6' => '', 
    90                         'link6' => '', 
    91                         'name7' => '', 
    92                         'link7' => '', 
    93                         'name8' => '', 
    94                         'link8' => '', 
    95                         'name9' => '', 
    96                         'link9' => '' 
     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, 
    97208                ) ); 
    98  
    99                 $title = htmlspecialchars($instance['title']); 
     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>'; 
    100242 
    101243                // Output the options 
    102244                echo '<p><label for="' . $this->get_field_name('title') . '">'. "\n"; 
    103                 echo __('Title:') . '<input style="width: 200px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>'. "\n"; 
    104                 echo '<label>' . __('Title') . '</label>' . '<label style="margin-left:120px;">' . __('URL') . '</label>' . "\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                "; 
    105255                for($i = 0; $i < 10; $i++) { 
    106                 echo '<p><input style="width: 100px;" id="' . $this->get_field_id('name' . $i) . '" name="' . $this->get_field_name('name' . $i) . '" type="text" value="' . $instance['name'. $i] . '" />:'. "\n"; 
    107                 echo '<input style="width: 280px;" id="' . $this->get_field_id('link' . $i) . '" name="' . $this->get_field_name('link' . $i) . '" type="text" value="' . $instance['link'. $i] . '" /></p>'. "\n"; 
     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>'; 
    108297                } 
     298                echo    '</table>'; 
    109299        } 
    110300 
Note: See TracChangeset for help on using the changeset viewer.