Dotclear

Changeset 3333:11107ba2fc59 for inc


Ignore:
Timestamp:
09/01/16 12:21:43 (9 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Cope with settings URLs for modules (defined in _define.php).
The settings URLs are displayed on the plugins maganement page, and at the bottom of each plugin main page if any (index.php).

The URLs are set in _define.php, as a new property using this schema:

'settings' => array( <list of URLs> )

With:

<list of URLs> = '<type>' => '<location>', …
<type> = 'self' (own plugin page), 'blog' (in blog parameters page) or 'pref' (in user preferences page)
<location> = (empty) or #<tab>[.<id>] with <tab> = id of the corresponding tab, and <id> = id of fieldset, h4, h5, field, … of first corresponding field

The list of URLs are displayed in the order defined in the array above.

Examples:

Antispam plugin:

'settings' => array(

'self' => ,
'blog' => '#params.antispam_params'

)

self → for main settings of the plugin on its own page (index.php)
blog → for secondary settings in the blog parameters

Tags plugin:

'settings' => array(

'pref' => '#user-options.tags_prefs'

)

pref → for tags list format in user preferences

Maintenance plugin:

'settings' => array(

'self' => '#settings'

)

self → "settings" tab of its own page (index.php)

Location:
inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.moduleslist.php

    r3327 r3333  
    466466                    'sshot'             => '', 
    467467                    'score'                  => 0, 
    468                     'type'                   => null 
     468                    'type'                   => null, 
     469                    'require'           => array(), 
     470                    'settings'               => array() 
    469471               ), 
    470472               # Module's values 
     
    744746                         if (!empty($more)) { 
    745747                              echo 
    746                               '<li>'.implode(' - ', $more).'</li>'; 
     748                              '<li>'.implode(' - ',$more).'</li>'; 
    747749                         } 
    748750 
     
    753755                    $config = !empty($module['root']) && file_exists(path::real($module['root'].'/_config.php')); 
    754756 
    755                     if ($config || !empty($module['section']) || !empty($module['tags'])) { 
     757                    if ($config || !empty($module['section']) || !empty($module['tags']) || !empty($module['settings'])) { 
    756758                         echo 
    757759                         '<div><ul class="mod-more">'; 
    758760 
    759                          if ($config) { 
    760                               echo 
    761                               '<li><a class="module-config" href="'.$this->getURL('module='.$id.'&amp;conf=1').'">'.__('Configure plugin').'</a></li>'; 
     761                         $settings = $this->getSettingsUrls($this->core,$id); 
     762                         if (!empty($settings)) { 
     763                              echo '<li>'.implode(' - ',$settings).'</li>'; 
    762764                         } 
    763765 
     
    806808 
    807809          return $this; 
     810     } 
     811 
     812     /** 
     813      * Get settings URLs if any 
     814      * 
     815      * @param object $core 
     816      * @param string $id module ID 
     817      * @param boolean $check check permission 
     818      * @param boolean $self include self URL (→ plugin index.php URL) 
     819      * @return Array of settings URLs 
     820      */ 
     821     public static function getSettingsUrls($core,$id,$check=false,$self=true) 
     822     { 
     823          $st = array(); 
     824 
     825          $config = !empty($core->plugins->moduleRoot($id)) && 
     826               file_exists(path::real($core->plugins->moduleRoot($id).'/_config.php')); 
     827          $settings = $core->plugins->moduleInfo($id,'settings'); 
     828          if ($config || !empty($settings)) { 
     829               if ($config) { 
     830                    $st[] = '<a class="module-config" href="'. 
     831                         $core->adminurl->get('admin.plugins',array('module' => $id,'conf' => '1')). 
     832                         '">'.__('Configure plugin').'</a>'; 
     833               } 
     834               if (is_array($settings)) { 
     835                    foreach ($settings as $sk => $sv) { 
     836                         switch ($sk) { 
     837                              case 'blog': 
     838                                   if ((!$check) || 
     839                                        ($check && $core->auth->check('admin',$core->blog->id))) { 
     840                                        $st[] = '<a class="module-config" href="'. 
     841                                             $core->adminurl->get('admin.blog.pref').$sv. 
     842                                             '">'.__('Plugin settings (in blog parameters)').'</a>'; 
     843                                   } 
     844                                   break; 
     845                              case 'pref': 
     846                                   if ((!$check) || 
     847                                        ($check && $core->auth->check('usage,contentadmin',$core->blog->id))) { 
     848                                        $st[] = '<a class="module-config" href="'. 
     849                                             $core->adminurl->get('admin.user.preferences').$sv. 
     850                                             '">'.__('Plugin settings (in user preferences)').'</a>'; 
     851                                   } 
     852                                   break; 
     853                              case 'self': 
     854                                   if ($self) { 
     855                                        if ((!$check) || 
     856                                             ($check && $core->auth->check($core->plugins->moduleInfo($id,'permissions'),$core->blog->id))) { 
     857                                             $st[] = '<a class="module-config" href="'. 
     858                                                  $core->adminurl->get('admin.plugin.'.$id).$sv. 
     859                                                  '">'.__('Plugin settings').'</a>'; 
     860                                        } 
     861                                   } 
     862                                   break; 
     863                         } 
     864                    } 
     865               } 
     866          } 
     867 
     868          return $st; 
    808869     } 
    809870 
  • inc/core/class.dc.modules.php

    r3135 r3333  
    283283     (currently available keys : permissions, priority, type) 
    284284     */ 
    285      public function registerModule($name,$desc,$author,$version, $properties = array()) 
     285     public function registerModule($name,$desc,$author,$version,$properties = array()) 
    286286     { 
    287287          if ($this->disabled_mode) { 
     
    320320                    'type' => null, 
    321321                    'enabled' => true, 
    322                     'requires' => array() 
     322                    'requires' => array(), 
     323                    'settings' => array() 
    323324               ), $properties 
    324325          ); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map