Dotclear

Changeset 2182:eaaf345b04f3


Ignore:
Timestamp:
10/01/13 09:44:02 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
dcRepo
Message:

Enable complex loop (get, post, redirect) in themes and plugins configuration files

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • admin/blog_theme.php

    r2175 r2182  
    6666} 
    6767 
    68 # -- Check for module configuration -- 
    69 $conf_file = false; 
    70 if (!empty($_REQUEST['conf']) && !empty($_REQUEST['module'])) { 
    71      if (!$core->themes->moduleExists($_REQUEST['module'])) { 
    72           $core->error->add(__('Unknow module ID')); 
    73      } 
    74      else { 
    75           $module = $core->themes->getModules($_REQUEST['module']); 
    76           $module = adminModulesList::parseModuleInfo($_REQUEST['module'], $module); 
    77  
    78           if (!file_exists(path::real($module['root'].'/_config.php'))) { 
    79                $core->error->add(__('This module has no configuration file.')); 
    80           } 
    81           else { 
    82                $conf_file = path::real($module['root'].'/_config.php'); 
    83           } 
    84      } 
    85 } 
    86  
    8768# -- Display module configuration page -- 
    88 if ($conf_file) { 
     69if ($list->setConfigurationFile($core->themes, $core->blog->settings->system->theme)) { 
     70 
     71     # Get content before page headers 
     72     include $list->getConfigurationFile(); 
     73 
     74     # Gather content 
     75     $list->setConfigurationContent(); 
     76 
     77     # Display page 
    8978     dcPage::open(__('Blog appearance'), 
     79          dcPage::jsPageTabs(). 
     80          dcPage::jsColorPicker(). 
    9081 
    9182          # --BEHAVIOR-- themesToolsHeaders 
    92           $core->callBehavior('themesToolsHeaders', $core, $module['id']), 
     83          $core->callBehavior('themesToolsHeaders', $core, true), 
    9384 
    9485          dcPage::breadcrumb( 
     
    10495     } 
    10596 
    106      try { 
    107           if (!$module['standalone_config']) { 
    108                echo 
    109                '<form id="module_config" action="'.$list->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'. 
    110                '<h3>'.sprintf(__('Configure theme "%s"'), html::escapeHTML($module['name'])).'</h3>'. 
    111                '<p><a class="back" href="'.$list->getPageURL().'#themes">'.__('Back').'</a></p>'; 
    112           } 
    113           define('DC_CONTEXT_THEME', true); 
    114  
    115           include $conf_file; 
    116  
    117           if (!$module['standalone_config']) { 
    118                echo 
    119                '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. 
    120                form::hidden('module', $module['id']). 
    121                $core->formNonce().'</p>'. 
    122                '</form>'; 
    123           } 
    124      } 
    125      catch (Exception $e) { 
    126           echo '<div class="error"><p>'.$e->getMessage().'</p></div>'; 
    127      } 
     97     # Display previously gathered content 
     98     $list->getConfigurationContent(); 
    12899 
    129100     dcPage::close(); 
  • admin/plugins.php

    r2175 r2182  
    6363)); 
    6464 
    65 # -- Check for module configuration -- 
    66 $conf_file = false; 
    67 if (!empty($_REQUEST['conf']) && !empty($_REQUEST['module'])) { 
    68      if (!$core->plugins->moduleExists($_REQUEST['module'])) { 
    69           $core->error->add(__('Unknow module ID')); 
    70      } 
    71      else { 
    72           $module = $core->plugins->getModules($_REQUEST['module']); 
    73           $module = adminModulesList::parseModuleInfo($_REQUEST['module'], $module); 
    74  
    75           if (!file_exists(path::real($module['root'].'/_config.php'))) { 
    76                $core->error->add(__('This module has no configuration file.')); 
    77           } 
    78           else { 
    79                $conf_file = path::real($module['root'].'/_config.php'); 
    80           } 
    81      } 
    82 } 
    83  
    8465# -- Display module configuration page -- 
    85 if ($conf_file) { 
     66if ($list->setConfigurationFile($core->plugins)) { 
     67 
     68     # Get content before page headers 
     69     include $list->getConfigurationFile(); 
     70 
     71     # Gather content 
     72     $list->setConfigurationContent(); 
     73 
     74     # Display page 
    8675     dcPage::open(__('Plugins management'), 
    8776 
    8877          # --BEHAVIOR-- pluginsToolsHeaders 
    89           $core->callBehavior('pluginsToolsHeaders', $core, $module['id']), 
     78          $core->callBehavior('pluginsToolsHeaders', $core, true), 
    9079 
    9180          dcPage::breadcrumb( 
     
    9786     ); 
    9887 
     88     # Message 
    9989     if (!empty($_GET['done'])){ 
    10090          dcPage::success(__('Plugin successfully configured.')); 
    10191     } 
    10292 
    103      try { 
    104           if (!$module['standalone_config']) { 
    105                echo 
    106                '<form id="module_config" action="'.$list->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'. 
    107                '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($module['name'])).'</h3>'. 
    108                '<p><a class="back" href="'.$list->getPageURL().'#plugins">'.__('Back').'</a></p>'; 
    109           } 
    110           define('DC_CONTEXT_PLUGIN', true); 
    111  
    112           include $conf_file; 
    113  
    114           if (!$module['standalone_config']) { 
    115                echo 
    116                '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. 
    117                form::hidden('module', $module['id']). 
    118                $core->formNonce().'</p>'. 
    119                '</form>'; 
    120           } 
    121      } 
    122      catch (Exception $e) { 
    123           echo '<div class="error"><p>'.$e->getMessage().'</p></div>'; 
    124      } 
     93     # Display previously gathered content 
     94     $list->getConfigurationContent(); 
    12595 
    12696     dcPage::close(); 
  • inc/admin/lib.moduleslist.php

    r2179 r2182  
    1010 
    1111     protected $list_id = 'unknow'; 
     12 
     13     protected $config_module = ''; 
     14     protected $config_file = ''; 
     15     protected $config_content = ''; 
    1216 
    1317     protected $path = false; 
     
    473477          } 
    474478 
     479          # Select (from repository) 
     480          if (in_array('choose', $actions) && $this->path_writable) { 
     481               $submits[] = '<input type="submit" name="choose" value="'.__('Choose').'" />'; 
     482          } 
     483 
    475484          # Parse form 
    476485          if (!empty($submits)) { 
     
    702711     } 
    703712 
     713     /** 
     714      * 
     715      * We need to get configuration content in three steps 
     716      * and out of this class to keep backward compatibility. 
     717      * 
     718      * if ($xxx->setConfigurationFile()) { 
     719      *   include $xxx->getConfigurationFile(); 
     720      * } 
     721      * $xxx->setConfigurationContent(); 
     722      * ... [put here page headers and other stuff] 
     723      * $xxx->getConfigurationContent(); 
     724      * 
     725      */ 
     726     public function setConfigurationFile(dcModules $modules, $id=null) 
     727     { 
     728          if (empty($_REQUEST['conf']) || empty($_REQUEST['module']) && !$id) { 
     729               return false; 
     730          } 
     731           
     732          if (!empty($_REQUEST['module']) && empty($id)) { 
     733               $id = $_REQUEST['module']; 
     734          } 
     735 
     736          if (!$modules->moduleExists($id)) { 
     737               $core->error->add(__('Unknow module ID')); 
     738               return false; 
     739          } 
     740 
     741          $module = $modules->getModules($id); 
     742          $module = self::parseModuleInfo($id, $module); 
     743          $file = path::real($module['root'].'/_config.php'); 
     744 
     745          if (!file_exists($file)) { 
     746               $core->error->add(__('This module has no configuration file.')); 
     747               return false; 
     748          } 
     749 
     750          $this->config_module = $module; 
     751          $this->config_file = $file; 
     752          $this->config_content = ''; 
     753 
     754          if (!defined('DC_CONTEXT_MODULE')) { 
     755               define('DC_CONTEXT_MODULE', true); 
     756          } 
     757 
     758          return true; 
     759     } 
     760 
     761     public function getConfigurationFile() 
     762     { 
     763          if (!$this->config_file) { 
     764               return null; 
     765          } 
     766 
     767          ob_start(); 
     768 
     769          return $this->config_file; 
     770     } 
     771 
     772     public function setConfigurationContent() 
     773     { 
     774          if ($this->config_file) { 
     775               $this->config_content = ob_get_contents(); 
     776          } 
     777 
     778          ob_end_clean(); 
     779 
     780          return !empty($this->file_content); 
     781     } 
     782 
     783     public function getConfigurationContent() 
     784     { 
     785          if (!$this->config_file) { 
     786               return null; 
     787          } 
     788 
     789          if (!$this->config_module['standalone_config']) { 
     790               echo 
     791               '<form id="module_config" action="'.$this->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'. 
     792               '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($this->config_module['name'])).'</h3>'. 
     793               '<p><a class="back" href="'.$this->getPageURL().'#plugins">'.__('Back').'</a></p>'; 
     794          } 
     795 
     796          echo $this->config_content; 
     797 
     798          if (!$this->config_module['standalone_config']) { 
     799               echo 
     800               '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. 
     801               form::hidden('module', $this->config_module['id']). 
     802               $this->core->formNonce().'</p>'. 
     803               '</form>'; 
     804          } 
     805 
     806          return true; 
     807     } 
     808 
    704809     public static function sanitizeString($str) 
    705810     { 
     
    828933               if ($current && $has_conf) { 
    829934                    $line .=  
    830                     '<a href="'.$this->getPageURL('conf=1').'" class="button">'.__('Configure theme').'</a> '; 
     935                    '<a href="'.$this->getPageURL('module='.$id.'&conf=1', false).'" class="button">'.__('Configure theme').'</a> '; 
    831936               } 
    832937               $line .=  
  • plugins/maintenance/_config.php

    r2165 r2182  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_CONTEXT_PLUGIN')) { return; } 
     12if (!defined('DC_CONTEXT_MODULE')) { return; } 
    1313 
    1414$core->blog->settings->addNamespace('maintenance'); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map