Dotclear

Changeset 2227:bfa7b3467627 for inc


Ignore:
Timestamp:
10/03/13 13:47:05 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
dcRepo
Message:

Continue clean and document code for plugins and themes admin pages

File:
1 edited

Legend:

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

    r2222 r2227  
    1212if (!defined('DC_ADMIN_CONTEXT')) { return; } 
    1313 
     14/** 
     15 * @ingroup DC_CORE 
     16 * @brief Helper for admin list of modules. 
     17 * @since 2.6 
     18 
     19 * Provides an object to parse XML feed of modules from a repository. 
     20 */ 
    1421class adminModulesList 
    1522{ 
    16      public $core; 
    17      public $modules; 
    18      public $store; 
    19  
    20      public static $allow_multi_install = false; 
    21      public static $distributed_modules = array(); 
    22  
    23      protected $list_id = 'unknow'; 
    24      protected $data = array(); 
    25  
    26      protected $config_module = ''; 
    27      protected $config_file = ''; 
    28      protected $config_content = ''; 
    29  
    30      protected $path = false; 
    31      protected $path_writable = false; 
    32      protected $path_pattern = false; 
    33  
    34      protected $page_url = 'plugins.php'; 
    35      protected $page_qs = '?'; 
    36      protected $page_tab = ''; 
    37  
    38      public static $nav_indexes = 'abcdefghijklmnopqrstuvwxyz0123456789'; 
    39      protected $nav_list = array(); 
    40      protected $nav_special = 'other'; 
    41  
    42      protected $sort_field = 'sname'; 
    43      protected $sort_asc = true; 
    44  
     23     public $core;       /**< @var object    dcCore instance */ 
     24     public $modules;    /**< @var object    dcModules instance */ 
     25     public $store;      /**< @var object    dcStore instance */ 
     26 
     27     public static $allow_multi_install = false;       /**< @var boolean   Work with multiple root directories */ 
     28     public static $distributed_modules = array();     /**< @var array     List of modules distributed with Dotclear */ 
     29 
     30     protected $list_id = 'unknow';     /**< @var string    Current list ID */ 
     31     protected $data = array();         /**< @var array     Current modules */ 
     32 
     33     protected $config_module = '';     /**< @var string    Module ID to configure */ 
     34     protected $config_file = '';  /**< @var string    Module path to configure */ 
     35     protected $config_content = '';    /**< @var string    Module configuration page content */ 
     36 
     37     protected $path = false;           /**< @var string    Modules root directory */ 
     38     protected $path_writable = false;  /**< @var boolean   Indicate if modules root directory is writable */ 
     39     protected $path_pattern = false;   /**< @var string    Directory pattern to work on */ 
     40 
     41     protected $page_url = 'plugins.php';    /**< @var string    Page URL */ 
     42     protected $page_qs = '?';                    /**< @var string    Page query string */ 
     43     protected $page_tab = '';                    /**< @var string    Page tab */ 
     44 
     45     public static $nav_indexes = 'abcdefghijklmnopqrstuvwxyz0123456789'; /**< @var  string    Index list */ 
     46     protected $nav_list = array();          /**< @var array     Index list with special index */ 
     47     protected $nav_special = 'other';  /**< @var string    Text for other special index */ 
     48 
     49     protected $sort_field = 'sname';   /**< @var string    Field used to sort modules */ 
     50     protected $sort_asc = true;             /**< @var boolean   Sort order asc */ 
     51 
     52     /** 
     53      * Constructor. 
     54      * 
     55      * Note that this creates dcStore instance. 
     56      * 
     57      * @param object    $modules       dcModules instance 
     58      * @param string    $modules_root  Modules root directories 
     59      * @param string    $xml_url       URL of modules feed from repository 
     60      */ 
    4561     public function __construct(dcModules $modules, $modules_root, $xml_url) 
    4662     { 
     
    4965          $this->store = new dcStore($modules, $xml_url); 
    5066 
    51           $this->setPathInfo($modules_root); 
    52           $this->setNavSpecial(__('other')); 
    53      } 
    54  
    55      public function newList($list_id) 
     67          $this->setPath($modules_root); 
     68          $this->setIndex(__('other')); 
     69     } 
     70 
     71     /** 
     72      * Begin a new list. 
     73      * 
     74      * @param string    $id       New list ID 
     75      * @return     adminModulesList self instance 
     76      */ 
     77     public function initList($id) 
    5678     { 
    5779          $this->data = array(); 
    5880          $this->page_tab = ''; 
    59           $this->list_id = $list_id; 
     81          $this->list_id = $id; 
    6082 
    6183          return $this; 
    6284     } 
    6385 
    64      protected function setPathInfo($root) 
     86     /// @name Modules root directory methods 
     87     //@{ 
     88     /** 
     89      * Set path info. 
     90      * 
     91      * @param string    $root          Modules root directories 
     92      * @return     adminModulesList self instance 
     93      */ 
     94     protected function setPath($root) 
    6595     { 
    6696          $paths = explode(PATH_SEPARATOR, $root); 
     
    77107     } 
    78108 
     109     /** 
     110      * Get modules root directory. 
     111      * 
     112      * @return     Path to work on 
     113      */ 
    79114     public function getPath() 
    80115     { 
     
    82117     } 
    83118 
    84      public function isPathWritable() 
     119     /** 
     120      * Check if modules root directory is writable. 
     121      * 
     122      * @return     True if directory is writable 
     123      */ 
     124     public function isWritablePath() 
    85125     { 
    86126          return $this->path_writable; 
    87127     } 
    88128 
    89      public function isPathDeletable($root) 
     129     /** 
     130      * Check if root directory of a module is deletable. 
     131      * 
     132      * @param string    $root          Module root directory 
     133      * @return     True if directory is delatable 
     134      */ 
     135     public function isDeletablePath($root) 
    90136     { 
    91137          return $this->path_writable  
     
    93139               && $this->core->auth->isSuperAdmin(); 
    94140     } 
    95  
    96      public function setPageURL($url) 
     141     //@} 
     142 
     143     /// @name Page methods 
     144     //@{ 
     145     /** 
     146      * Set page base URL. 
     147      * 
     148      * @param string    $url      Page base URL 
     149      * @return     adminModulesList self instance 
     150      */ 
     151     public function setURL($url) 
    97152     { 
    98153          $this->page_qs = strpos('?', $url) ? '&' : '?'; 
     
    102157     } 
    103158 
    104      public function getPageURL($queries='', $with_tab=true) 
     159     /** 
     160      * Get page URL. 
     161      * 
     162      * @param string|array   $queries  Additionnal query string 
     163      * @param booleany  $with_tab      Add current tab to URL end 
     164      * @return     Clean page URL 
     165      */ 
     166     public function getURL($queries='', $with_tab=true) 
    105167     { 
    106168          return $this->page_url. 
     
    110172     } 
    111173 
    112      public function setPageTab($tab) 
     174     /** 
     175      * Set page tab. 
     176      * 
     177      * @param string    $tab      Page tab 
     178      * @return     adminModulesList self instance 
     179      */ 
     180     public function setTab($tab) 
    113181     { 
    114182          $this->page_tab = $tab; 
     
    117185     } 
    118186 
    119      public function getPageTab() 
     187     /** 
     188      * Get page tab. 
     189      * 
     190      * @return     Page tab 
     191      */ 
     192     public function getTab() 
    120193     { 
    121194          return $this->page_tab; 
    122195     } 
    123  
    124      public function getSearchQuery() 
     196     //@} 
     197 
     198     /// @name Search methods 
     199     //@{ 
     200     /** 
     201      * Get search query. 
     202      * 
     203      * @return     Search query 
     204      */ 
     205     public function getSearch() 
    125206     { 
    126207          $query = !empty($_REQUEST['m_search']) ? trim($_REQUEST['m_search']) : null; 
    127           return strlen($query) > 1 ? $query : null; 
    128      } 
    129  
    130      public function displaySearchForm() 
    131      { 
    132           $query = $this->getSearchQuery(); 
     208          return strlen($query) > 2 ? $query : null; 
     209     } 
     210 
     211     /** 
     212      * Display searh form. 
     213      * 
     214      * @return     adminModulesList self instance 
     215      */ 
     216     public function displaySearch() 
     217     { 
     218          $query = $this->getSearch(); 
    133219 
    134220          if (empty($this->data) && $query === null) { 
     
    137223 
    138224          echo  
    139           '<form action="'.$this->getPageURL().'" method="get" class="fieldset">'. 
     225          '<form action="'.$this->getURL().'" method="get" class="fieldset">'. 
    140226          '<p><label for="m_search" class="classic">'.__('Search in repository:').'&nbsp;</label><br />'. 
    141227          form::field(array('m_search','m_search'), 30, 255, html::escapeHTML($query)). 
    142228          '<input type="submit" value="'.__('Search').'" /> '; 
    143           if ($query) { echo ' <a href="'.$this->getPageURL().'" class="button">'.__('Reset search').'</a>'; } 
     229          if ($query) { echo ' <a href="'.$this->getURL().'" class="button">'.__('Reset search').'</a>'; } 
    144230          echo '</p>'. 
    145231          '</form>'; 
     
    155241          return $this; 
    156242     } 
    157  
    158      public function setNavSpecial($str) 
     243     //@} 
     244 
     245     /// @name Navigation menu methods 
     246     //@{ 
     247     /** 
     248      * Set navigation special index. 
     249      * 
     250      * @return     adminModulesList self instance 
     251      */ 
     252     public function setIndex($str) 
    159253     { 
    160254          $this->nav_special = (string) $str; 
     
    164258     } 
    165259 
    166      public function getNavQuery() 
     260     /** 
     261      * Get index from query. 
     262      * 
     263      * @return     Query index or default one 
     264      */ 
     265     public function getIndex() 
    167266     { 
    168267          return isset($_REQUEST['m_nav']) && in_array($_REQUEST['m_nav'], $this->nav_list) ? $_REQUEST['m_nav'] : $this->nav_list[0]; 
    169268     } 
    170269 
    171      public function displayNavMenu() 
    172      { 
    173           if (empty($this->data) || $this->getSearchQuery() !== null) { 
     270     /** 
     271      * Display navigation by index menu. 
     272      * 
     273      * @return     adminModulesList self instance 
     274      */ 
     275     public function displayIndex() 
     276     { 
     277          if (empty($this->data) || $this->getSearch() !== null) { 
    174278               return $this; 
    175279          } 
     
    194298          foreach($this->nav_list as $char) { 
    195299               # Selected letter 
    196                if ($this->getNavQuery() == $char) { 
     300               if ($this->getIndex() == $char) { 
    197301                    $buttons[] = '<li class="active" title="'.__('current selection').'"><strong> '.$char.' </strong></li>'; 
    198302               } 
     
    200304               elseif (!empty($indexes[$char])) { 
    201305                    $title = sprintf(__('%d module', '%d modules', $indexes[$char]), $indexes[$char]); 
    202                     $buttons[] = '<li class="btn" title="'.$title.'"><a href="'.$this->getPageURL('m_nav='.$char).'" title="'.$title.'"> '.$char.' </a></li>'; 
     306                    $buttons[] = '<li class="btn" title="'.$title.'"><a href="'.$this->getURL('m_nav='.$char).'" title="'.$title.'"> '.$char.' </a></li>'; 
    203307               } 
    204308               # Letter without modules 
     
    212316          return $this; 
    213317     } 
    214  
    215      public function setSortField($field, $asc=true) 
     318     //@} 
     319 
     320     /// @name Sort methods 
     321     //@{ 
     322     /** 
     323      * Set default sort field. 
     324      * 
     325      * @return     adminModulesList self instance 
     326      */ 
     327     public function setSort($field, $asc=true) 
    216328     { 
    217329          $this->sort_field = $field; 
     
    221333     } 
    222334 
    223      public function getSortQuery() 
     335     /** 
     336      * Get sort field from query. 
     337      * 
     338      * @return     Query sort field or default one 
     339      */ 
     340     public function getSort() 
    224341     { 
    225342          return !empty($_REQUEST['m_sort']) ? $_REQUEST['m_sort'] : $this->sort_field; 
    226343     } 
    227344 
    228      public function displaySortForm() 
    229      { 
    230           //not yet implemented 
    231      } 
    232  
     345     /** 
     346      * Display sort field form. 
     347      * 
     348      * @note  This method is not implemented yet 
     349      * @return     adminModulesList self instance 
     350      */ 
     351     public function displaySort() 
     352     { 
     353          // 
     354 
     355          return $this; 
     356     } 
     357     //@} 
     358 
     359     /// @name Modules methods 
     360     //@{ 
     361     /** 
     362      * Set modules and sanitize them. 
     363      * 
     364      * @return     adminModulesList self instance 
     365      */ 
    233366     public function setModules($modules) 
    234367     { 
     
    236369          if (!empty($modules) && is_array($modules)) { 
    237370               foreach($modules as $id => $module) { 
    238                     $this->data[$id] = self::parseModuleInfo($id, $module); 
     371                    $this->data[$id] = self::sanitizeModule($id, $module); 
    239372               } 
    240373          } 
     
    242375     } 
    243376 
     377     /** 
     378      * Get modules currently set. 
     379      * 
     380      * @return     Array of modules 
     381      */ 
    244382     public function getModules() 
    245383     { 
     
    247385     } 
    248386 
    249      public static function parseModuleInfo($id, $module) 
     387     /** 
     388      * Sanitize a module. 
     389      * 
     390      * This clean infos of a module by adding default keys  
     391      * and clean some of them, sanitize module can safely  
     392      * be used in lists. 
     393      * 
     394      * @return     Array of the module informations 
     395      */ 
     396     public static function sanitizeModule($id, $module) 
    250397     { 
    251398          $label = empty($module['label']) ? $id : $module['label']; 
     
    285432     } 
    286433 
    287      public static function isDistributedModule($module) 
     434     /** 
     435      * Check if a module is part of the distribution. 
     436      * 
     437      * @param string    $id       Module root directory 
     438      * @return     True if module is part of the distribution 
     439      */ 
     440     public static function isDistributedModule($id) 
    288441     { 
    289442          $distributed_modules = self::$distributed_modules; 
    290443 
    291           return is_array($distributed_modules) && in_array($module, $distributed_modules); 
    292      } 
    293  
     444          return is_array($distributed_modules) && in_array($id, $distributed_modules); 
     445     } 
     446 
     447     /** 
     448      * Sort modules list by specific field. 
     449      * 
     450      * @param string    $module        Array of modules 
     451      * @param string    $field         Field to sort from 
     452      * @param bollean   $asc      Sort asc if true, else decs 
     453      * @return     Array of sorted modules 
     454      */ 
    294455     public static function sortModules($modules, $field, $asc=true) 
    295456     { 
     
    303464     } 
    304465 
    305      public function displayModulesList($cols=array('name', 'config', 'version', 'desc'), $actions=array(), $nav_limit=false) 
     466     /** 
     467      * Display list of modules. 
     468      * 
     469      * @param array     $cols          List of colones (module field) to display 
     470      * @param array     $actions  List of predefined actions to show on form 
     471      * @param boolean   $nav_limit     Limit list to previously selected index 
     472      * @return     adminModulesList self instance 
     473      */ 
     474     public function displayModules($cols=array('name', 'version', 'desc'), $actions=array(), $nav_limit=false) 
    306475     { 
    307476          echo  
     
    315484          } 
    316485 
    317           if (in_array('score', $cols) && $this->getSearchQuery() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
     486          if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
    318487               echo  
    319488               '<th class="nowrap">'.__('Score').'</th>'; 
     
    347516          '</tr>'; 
    348517 
    349           $sort_field = $this->getSortQuery(); 
     518          $sort_field = $this->getSort(); 
    350519 
    351520          # Sort modules by $sort_field (default sname) 
    352           $modules = $this->getSearchQuery() === null ? 
     521          $modules = $this->getSearch() === null ? 
    353522               self::sortModules($this->data, $sort_field, $this->sort_asc) : 
    354523               $this->data; 
     
    358527          { 
    359528               # Show only requested modules 
    360                if ($nav_limit && $this->getSearchQuery() === null) { 
     529               if ($nav_limit && $this->getSearch() === null) { 
    361530                    $char = substr($module[$sort_field], 0, 1); 
    362531                    if (!in_array($char, $this->nav_list)) { 
    363532                         $char = $this->nav_special; 
    364533                    } 
    365                     if ($this->getNavQuery() != $char) { 
     534                    if ($this->getIndex() != $char) { 
    366535                         continue; 
    367536                    } 
     
    384553               echo  
    385554               '<td class="module-name nowrap" scope="row">'.($config ?  
    386                     '<a href="'.$this->getPageURL('module='.$id.'&conf=1').'" title"'.sprintf(__('Configure module "%s"'), html::escapeHTML($module['name'])).'">'.html::escapeHTML($module['name']).'</a>' :  
     555                    '<a href="'.$this->getURL('module='.$id.'&conf=1').'" title"'.sprintf(__('Configure module "%s"'), html::escapeHTML($module['name'])).'">'.html::escapeHTML($module['name']).'</a>' :  
    387556                    html::escapeHTML($module['name']) 
    388557               ).'</td>'; 
    389558 
    390559               # Display score only for debug purpose 
    391                if (in_array('score', $cols) && $this->getSearchQuery() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
     560               if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
    392561                    echo  
    393562                    '<td class="module-version nowrap count"><span class="debug">'.$module['score'].'</span></td>'; 
     
    424593                    '<td class="module-actions nowrap">'. 
    425594 
    426                     '<form action="'.$this->getPageURL().'" method="post">'. 
     595                    '<form action="'.$this->getURL().'" method="post">'. 
    427596                    '<div>'. 
    428597                    $this->core->formNonce(). 
    429598                    form::hidden(array('module'), html::escapeHTML($id)). 
    430                     form::hidden(array('tab'), $this->page_tab). 
    431599 
    432600                    implode(' ', $buttons). 
     
    446614          '</table></div>'; 
    447615 
    448           if(!$count && $this->getSearchQuery() === null) { 
     616          if(!$count && $this->getSearch() === null) { 
    449617               echo  
    450618               '<p class="message">'.__('No module matches your search.').'</p>'; 
    451619          } 
    452      } 
    453  
     620 
     621          return $this; 
     622     } 
     623 
     624     /** 
     625      * Get action buttons to add to modules list. 
     626      * 
     627      * @param string    $id            Module ID 
     628      * @param array     $module        Module info 
     629      * @param array     $actions  Actions keys 
     630      * @return     Array of actions buttons 
     631      */ 
    454632     protected function getActions($id, $module, $actions) 
    455633     { 
     
    473651 
    474652                    # Delete 
    475                     case 'delete': if ($this->isPathDeletable($module['root'])) { 
     653                    case 'delete': if ($this->isDeletablePath($module['root'])) { 
    476654                         $submits[] =  
    477655                         '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; 
     
    495673     } 
    496674 
     675     /** 
     676      * Execute POST action. 
     677      * 
     678      * @note  Set a notice on success through dcPage::addSuccessNotice 
     679      * @throw Exception Module not find or command failed 
     680      * @param string    $prefix        Prefix used on behaviors 
     681      * @return     Null 
     682      */ 
    497683     public function doActions($prefix) 
    498684     { 
    499685          if (empty($_POST) || !empty($_REQUEST['conf'])  
    500           || !$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 
     686          || !$this->core->auth->isSuperAdmin() || !$this->isWritablePath()) { 
    501687               return null; 
    502688          } 
     
    523709 
    524710                    dcPage::addSuccessNotice(__('Module has been successfully activated.')); 
    525                     http::redirect($this->getPageURL()); 
     711                    http::redirect($this->getURL()); 
    526712               } 
    527713 
     
    548734 
    549735                    dcPage::addSuccessNotice(__('Module has been successfully deactivated.')); 
    550                     http::redirect($this->getPageURL()); 
     736                    http::redirect($this->getURL()); 
    551737               } 
    552738 
     
    563749                         $module['id'] = $id; 
    564750 
    565                          if (!$this->isPathDeletable($module['root'])) { 
     751                         if (!$this->isDeletablePath($module['root'])) { 
    566752                              throw new Exception(__("You don't have permissions to delete this module.")); 
    567753                         } 
     
    580766 
    581767                    dcPage::addSuccessNotice(__('Module has been successfully deleted.')); 
    582                     http::redirect($this->getPageURL()); 
     768                    http::redirect($this->getURL()); 
    583769               } 
    584770 
     
    607793                         __('Module has been successfully installed.') 
    608794                    ); 
    609                     http::redirect($this->getPageURL()); 
     795                    http::redirect($this->getURL()); 
    610796               } 
    611797 
     
    623809                    $module = $updated[$id]; 
    624810                    $module['id'] = $id; 
    625                 
     811 
    626812                    if (!self::$allow_multi_install) { 
    627813                         $dest = $module['root'].'/../'.basename($module['file']); 
     
    643829 
    644830                    dcPage::addSuccessNotice(__('Module has been successfully updated.')); 
    645                     http::redirect($this->getPageURL()); 
     831                    http::redirect($this->getURL()); 
    646832               } 
    647833          } 
     
    680866                    __('Module has been successfully installed.') 
    681867               ); 
    682                http::redirect($this->getPageURL().'#'.$prefix); 
     868               http::redirect($this->getURL().'#'.$prefix); 
    683869          } 
    684870 
     
    686872     } 
    687873 
     874     /** 
     875      * Display tab for manual installation. 
     876      * 
     877      * @return     adminModulesList self instance 
     878      */ 
    688879     public function displayManualForm() 
    689880     { 
    690           if (!$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 
     881          if (!$this->core->auth->isSuperAdmin() || !$this->isWritablePath()) { 
    691882               return null; 
    692883          } 
     
    694885          # 'Upload module' form 
    695886          echo 
    696           '<form method="post" action="'.$this->getPageURL().'" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. 
     887          '<form method="post" action="'.$this->getURL().'" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. 
    697888          '<h4>'.__('Upload a zip file').'</h4>'. 
    698889          '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file path:').'</label> '. 
     
    701892          form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. 
    702893          '<p><input type="submit" name="upload_pkg" value="'.__('Upload').'" />'. 
    703           form::hidden(array('tab'), $this->getPageTab()). 
    704894          $this->core->formNonce().'</p>'. 
    705895          '</form>'; 
    706            
     896 
    707897          # 'Fetch module' form 
    708898          echo 
    709           '<form method="post" action="'.$this->getPageURL().'" id="fetchpkg" class="fieldset">'. 
     899          '<form method="post" action="'.$this->getURL().'" id="fetchpkg" class="fieldset">'. 
    710900          '<h4>'.__('Download a zip file').'</h4>'. 
    711901          '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file URL:').'</label> '. 
     
    714904          form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. 
    715905          '<p><input type="submit" name="fetch_pkg" value="'.__('Download').'" />'. 
    716           form::hidden(array('tab'), $this->getPageTab()). 
    717906          $this->core->formNonce().'</p>'. 
    718907          '</form>'; 
    719      } 
    720  
    721      /** 
     908 
     909          return $this; 
     910     } 
     911     //@} 
     912 
     913     /// @name Module configuration methods 
     914     //@{ 
     915     /** 
     916      * Prepare module configuration. 
    722917      * 
    723918      * We need to get configuration content in three steps 
    724919      * and out of this class to keep backward compatibility. 
    725920      * 
    726       * if ($xxx->setConfigurationFile()) { 
    727       *   include $xxx->getConfigurationFile(); 
     921      * if ($xxx->setConfiguration()) { 
     922      *   include $xxx->includeConfiguration(); 
    728923      * } 
    729       * $xxx->setConfigurationContent(); 
     924      * $xxx->getConfiguration(); 
    730925      * ... [put here page headers and other stuff] 
    731       * $xxx->getConfigurationContent(); 
    732       * 
    733       */ 
    734      public function setConfigurationFile($id=null) 
     926      * $xxx->displayConfiguration(); 
     927      * 
     928      * @param string    $id       Module to work on or it gather through REQUEST 
     929      * @return     True if config set 
     930      */ 
     931     public function setConfiguration($id=null) 
    735932     { 
    736933          if (empty($_REQUEST['conf']) || empty($_REQUEST['module']) && !$id) { 
     
    748945 
    749946          $module = $this->modules->getModules($id); 
    750           $module = self::parseModuleInfo($id, $module); 
     947          $module = self::sanitizeModule($id, $module); 
    751948          $file = path::real($module['root'].'/_config.php'); 
    752949 
     
    767964     } 
    768965 
    769      public function getConfigurationFile() 
     966     /** 
     967      * Get path of module configuration file. 
     968      * 
     969      * @note Required previously set file info 
     970      * @return Full path of config file or null 
     971      */ 
     972     public function includeConfiguration() 
    770973     { 
    771974          if (!$this->config_file) { 
     
    778981     } 
    779982 
    780      public function setConfigurationContent() 
     983     /** 
     984      * Gather module configuration file content. 
     985      * 
     986      * @note Required previously file inclusion 
     987      * @return True if content has been captured 
     988      */ 
     989     public function getConfiguration() 
    781990     { 
    782991          if ($this->config_file) { 
     
    789998     } 
    790999 
    791      public function getConfigurationContent() 
    792      { 
    793           if (!$this->config_file) { 
    794                return null; 
    795           } 
    796  
    797           if (!$this->config_module['standalone_config']) { 
    798                echo 
    799                '<form id="module_config" action="'.$this->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'. 
    800                '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($this->config_module['name'])).'</h3>'. 
    801                '<p><a class="back" href="'.$this->getPageURL().'#plugins">'.__('Back').'</a></p>'; 
    802           } 
    803  
    804           echo $this->config_content; 
    805  
    806           if (!$this->config_module['standalone_config']) { 
    807                echo 
    808                '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. 
    809                form::hidden('module', $this->config_module['id']). 
    810                $this->core->formNonce().'</p>'. 
    811                '</form>'; 
    812           } 
    813  
    814           return true; 
    815      } 
    816  
     1000     /** 
     1001      * Display module configuration form. 
     1002      * 
     1003      * @note Required previously gathered content 
     1004      * @return     adminModulesList self instance 
     1005      */ 
     1006     public function displayConfiguration() 
     1007     { 
     1008          if ($this->config_file) { 
     1009 
     1010               if (!$this->config_module['standalone_config']) { 
     1011                    echo 
     1012                    '<form id="module_config" action="'.$this->getURL('conf=1').'" method="post" enctype="multipart/form-data">'. 
     1013                    '<h3>'.sprintf(__('Configure plugin "%s"'), html::escapeHTML($this->config_module['name'])).'</h3>'. 
     1014                    '<p><a class="back" href="'.$this->getURL().'#plugins">'.__('Back').'</a></p>'; 
     1015               } 
     1016 
     1017               echo $this->config_content; 
     1018 
     1019               if (!$this->config_module['standalone_config']) { 
     1020                    echo 
     1021                    '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. 
     1022                    form::hidden('module', $this->config_module['id']). 
     1023                    $this->core->formNonce().'</p>'. 
     1024                    '</form>'; 
     1025               } 
     1026          } 
     1027 
     1028          return $this; 
     1029     } 
     1030     //@} 
     1031 
     1032     /** 
     1033      * Helper to sanitize a string. 
     1034      * 
     1035      * Used for search or id. 
     1036      * 
     1037      * @param string    $str      String to sanitize 
     1038      * @return     Sanitized string 
     1039      */ 
    8171040     public static function sanitizeString($str) 
    8181041     { 
     
    8211044} 
    8221045 
     1046/** 
     1047 * @ingroup DC_CORE 
     1048 * @brief Helper to manage list of themes. 
     1049 * @since 2.6 
     1050 */ 
    8231051class adminThemesList extends adminModulesList 
    8241052{ 
    8251053     protected $page_url = 'blog_theme.php'; 
    8261054 
    827      public function displayModulesList($cols=array('name', 'config', 'version', 'desc'), $actions=array(), $nav_limit=false) 
     1055     public function displayModules($cols=array('name', 'config', 'version', 'desc'), $actions=array(), $nav_limit=false) 
    8281056     { 
    8291057          echo  
    8301058          '<div id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').' one-box">'; 
    8311059 
    832           $sort_field = $this->getSortQuery(); 
     1060          $sort_field = $this->getSort(); 
    8331061 
    8341062          # Sort modules by id 
    835           $modules = $this->getSearchQuery() === null ? 
     1063          $modules = $this->getSearch() === null ? 
    8361064               self::sortModules($this->data, $sort_field, $this->sort_asc) : 
    8371065               $this->data; 
     
    8421070          { 
    8431071               # Show only requested modules 
    844                if ($nav_limit && $this->getSearchQuery() === null) { 
     1072               if ($nav_limit && $this->getSearch() === null) { 
    8451073                    $char = substr($module[$sort_field], 0, 1); 
    8461074                    if (!in_array($char, $this->nav_list)) { 
    8471075                         $char = $this->nav_special; 
    8481076                    } 
    849                     if ($this->getNavQuery() != $char) { 
     1077                    if ($this->getIndex() != $char) { 
    8501078                         continue; 
    8511079                    } 
    8521080               } 
    8531081 
    854                $current = $this->core->blog->settings->system->theme == $id; 
     1082               $current = $this->core->blog->settings->system->theme == $id && $this->modules->moduleExists($id); 
    8551083               $distrib = self::isDistributedModule($id) ? ' dc-box' : ''; 
    856  
    857                $theme_url = preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url) ? 
    858                     http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id) : 
    859                     http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id); 
    860  
    861                $has_conf = file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/_config.php'); 
    862                $has_css = file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/style.css'); 
    863                $parent = $module['parent']; 
    864                $has_parent = !empty($module['parent']); 
    865                if ($has_parent) { 
    866                     $is_parent_present = $this->modules->moduleExists($parent); 
    867                } 
    8681084 
    8691085               $line =  
     
    8761092 
    8771093               # Display score only for debug purpose 
    878                if (in_array('score', $cols) && $this->getSearchQuery() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
     1094               if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) { 
    8791095                    $line .=  
    8801096                    '<p class="module-score debug">'.sprintf(__('Score: %s'), $module['score']).'</p>'; 
     
    8881104                    # Screenshot from installed module 
    8891105                    elseif (file_exists($this->core->blog->themes_path.'/'.$id.'/screenshot.jpg')) { 
    890                          $sshot = $this->getPageURL('shot='.rawurlencode($id)); 
     1106                         $sshot = $this->getURL('shot='.rawurlencode($id)); 
    8911107                    } 
    8921108                    # Default screenshot 
     
    9241140               } 
    9251141 
    926                if (in_array('parent', $cols) && $has_parent) { 
    927                     if ($is_parent_present) { 
     1142               if (in_array('parent', $cols) && !empty($module['parent'])) { 
     1143                    if ($this->modules->moduleExists($module['parent'])) { 
    9281144                         $line .=  
    929                          '<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> '; 
     1145                         '<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($module['parent'])).'</span> '; 
    9301146                    } 
    9311147                    else { 
    9321148                         $line .=  
    933                          '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 
     1149                         '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($module['parent'])).'</span> '; 
    9341150                    } 
    9351151               } 
     
    9621178               '<div class="module-actions toggle-bloc">'; 
    9631179                
    964                # _GET actions 
    965  
    966                if ($current && $has_css) { 
    967                     $line .=  
    968                     '<p><a href="'.$theme_url.'/style.css">'.__('View stylesheet').'</a></p>'; 
    969                } 
    970                if ($current && $has_conf) { 
    971                     $line .=  
    972                     '<p><a href="'.$this->getPageURL('module='.$id.'&conf=1', false).'" class="button">'.__('Configure theme').'</a></p>'; 
    973                } 
    974  
    9751180               # Plugins actions 
    9761181               if ($current) { 
     1182 
     1183                    # _GET actions 
     1184                    if (file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/style.css')) { 
     1185                         $theme_url = preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url) ? 
     1186                              http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id) : 
     1187                              http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id); 
     1188                         $line .=  
     1189                         '<p><a href="'.$theme_url.'/style.css">'.__('View stylesheet').'</a></p>'; 
     1190                    } 
     1191 
     1192                    if (file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/_config.php')) { 
     1193                         $line .=  
     1194                         '<p><a href="'.$this->getURL('module='.$id.'&conf=1', false).'" class="button">'.__('Configure theme').'</a></p>'; 
     1195                    } 
     1196 
    9771197                    # --BEHAVIOR-- adminCurrentThemeDetails 
    9781198                    $line .=  
     
    9831203               if (!empty($actions)) { 
    9841204                    $line .= 
    985                     '<form action="'.$this->getPageURL().'" method="post">'. 
     1205                    '<form action="'.$this->getURL().'" method="post">'. 
    9861206                    '<div>'. 
    9871207                    $this->core->formNonce(). 
    9881208                    form::hidden(array('module'), html::escapeHTML($id)). 
    989                     form::hidden(array('tab'), $this->page_tab). 
    9901209 
    9911210                    implode(' ', $this->getActions($id, $module, $actions)). 
     
    10091228          '</div>'; 
    10101229 
    1011           if(!$count && $this->getSearchQuery() === null) { 
     1230          if(!$count && $this->getSearch() === null) { 
    10121231               echo  
    10131232               '<p class="message">'.__('No module matches your search.').'</p>'; 
     
    10241243               # Select theme to use on curent blog 
    10251244               if (in_array('select', $actions) && $this->path_writable) { 
    1026                     $submits[] = '<input type="submit" name="select" value="'.__('Choose').'" />'; 
     1245                    $submits[] =  
     1246                    '<input type="submit" name="select" value="'.__('Use this one').'" />'; 
    10271247               } 
    10281248          } 
     
    10361256     public function doActions($prefix) 
    10371257     { 
    1038           if (!empty($_POST) && empty($_REQUEST['conf']) && $this->isPathWritable()) { 
     1258          if (!empty($_POST) && empty($_REQUEST['conf']) && $this->isWritablePath()) { 
    10391259 
    10401260               # Select theme to use on curent blog 
     
    10511271 
    10521272                    dcPage::addSuccessNotice(__('Module has been successfully selected.')); 
    1053                     http::redirect($this->getPageURL().'#themes'); 
     1273                    http::redirect($this->getURL().'#themes'); 
    10541274               } 
    10551275          } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map