Dotclear


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

Next step for themes manager, to be continued

File:
1 edited

Legend:

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

    r2182 r2192  
    442442          '</table></div>'; 
    443443 
    444           if(!$count) { 
     444          if(!$count && $this->getSearchQuery() === null) { 
    445445               echo  
    446446               '<p class="message">'.__('No module matches your search.').'</p>'; 
     
    451451     { 
    452452          $submits = array(); 
     453 
     454          # Update (from repository) 
     455          if (in_array('update', $actions) && $this->path_writable) { 
     456               $submits[] = '<input type="submit" name="update" value="'.__('Update').'" />'; 
     457          } 
     458 
     459          # Install (form repository) 
     460          if (in_array('install', $actions) && $this->path_writable) { 
     461               $submits[] = '<input type="submit" name="install" value="'.__('Install').'" />'; 
     462          } 
     463           
     464          $tmp = $this->displayOtherLineAction($id, $module, $actions); 
     465          if (!empty($tmp) && is_array($tmp)) { 
     466               $submits = array_merge($submits, $tmp); 
     467          } 
    453468 
    454469          # Activate 
     
    465480          if (in_array('delete', $actions) && $this->isPathDeletable($module['root'])) { 
    466481               $submits[] = '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; 
    467           } 
    468  
    469           # Install (form repository) 
    470           if (in_array('install', $actions) && $this->path_writable) { 
    471                $submits[] = '<input type="submit" name="install" value="'.__('Install').'" />'; 
    472           } 
    473  
    474           # Update (from repository) 
    475           if (in_array('update', $actions) && $this->path_writable) { 
    476                $submits[] = '<input type="submit" name="update" value="'.__('Update').'" />'; 
    477           } 
    478  
    479           # Select (from repository) 
    480           if (in_array('choose', $actions) && $this->path_writable) { 
    481                $submits[] = '<input type="submit" name="choose" value="'.__('Choose').'" />'; 
    482482          } 
    483483 
     
    501501     } 
    502502 
     503     protected function displayOtherLineAction($id, $module, $actions) 
     504     { 
     505          return null; 
     506     } 
     507 
    503508     public function executeAction($prefix, dcModules $modules, dcRepository $repository) 
    504509     { 
     
    520525 
    521526                    # --BEHAVIOR-- moduleBeforeActivate 
    522                     $this->core->callBehavior($type.'BeforeActivate', $id); 
     527                    $this->core->callBehavior($prefix.'BeforeActivate', $id); 
    523528 
    524529                    $modules->activateModule($id); 
    525530 
    526531                    # --BEHAVIOR-- moduleAfterActivate 
    527                     $this->core->callBehavior($type.'AfterActivate', $id); 
     532                    $this->core->callBehavior($prefix.'AfterActivate', $id); 
    528533 
    529534                    http::redirect($this->getPageURL('msg=activate')); 
    530535               } 
    531536 
    532                if (!empty($_POST['deactivate'])) { 
     537               elseif (!empty($_POST['deactivate'])) { 
    533538 
    534539                    if (!$modules->moduleExists($id)) { 
     
    554559               } 
    555560 
    556                if (!empty($_POST['delete'])) { 
     561               elseif (!empty($_POST['delete'])) { 
    557562 
    558563                    $disabled = $modules->getDisabledModules(); 
     
    585590               } 
    586591 
    587                if (!empty($_POST['update'])) { 
     592               elseif (!empty($_POST['update'])) { 
    588593 
    589594                    $updated = $repository->get(); 
     
    610615 
    611616                    # --BEHAVIOR-- moduleBeforeUpdate 
    612                     $this->core->callBehavior($type.'BeforeUpdate', $module); 
     617                    $this->core->callBehavior($prefix.'BeforeUpdate', $module); 
    613618 
    614619                    $repository->process($module['file'], $dest); 
    615620 
    616621                    # --BEHAVIOR-- moduleAfterUpdate 
    617                     $this->core->callBehavior($type.'AfterUpdate', $module); 
     622                    $this->core->callBehavior($prefix.'AfterUpdate', $module); 
    618623 
    619624                    http::redirect($this->getPageURL('msg=upadte')); 
    620625               } 
    621626 
    622                if (!empty($_POST['install'])) { 
     627               elseif (!empty($_POST['install'])) { 
    623628 
    624629                    $updated = $repository->get(); 
     
    633638 
    634639                    # --BEHAVIOR-- moduleBeforeAdd 
    635                     $this->core->callBehavior($type.'BeforeAdd', $module); 
     640                    $this->core->callBehavior($prefix.'BeforeAdd', $module); 
    636641 
    637642                    $ret_code = $repository->process($module['file'], $dest); 
    638643 
    639644                    # --BEHAVIOR-- moduleAfterAdd 
    640                     $this->core->callBehavior($type.'AfterAdd', $module); 
     645                    $this->core->callBehavior($prefix.'AfterAdd', $module); 
    641646 
    642647                    http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install'))); 
     
    675680               http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install')).'#'.$prefix); 
    676681          } 
     682 
     683          return $this->executeOtherAction($prefix, $modules, $repository); 
     684     } 
     685 
     686     /** 
     687      *  
     688      * Way for child class to execute their own actions  
     689      * whitout rewriting all standard actions. 
     690      */ 
     691     protected function executeOtherAction($prefix, dcModules $modules, dcRepository $repository) 
     692     { 
    677693          return null; 
    678694     } 
     
    863879               '<div class="box small '.($current ? 'current-theme' : 'theme').'">'; 
    864880 
     881               if (in_array('name', $cols)) { 
     882                    $line .=  
     883                    '<h4 class="module-name">'.html::escapeHTML($module['name']).'</h4>'; 
     884               } 
     885 
     886               $line .=  
     887               '<div class="module-infos">'. 
     888               '<p>'; 
     889 
     890               if (in_array('desc', $cols)) { 
     891                    $line .=  
     892                    '<span class="module-desc">'.html::escapeHTML($module['desc']).'</span> '; 
     893               } 
     894 
     895               if (in_array('author', $cols)) { 
     896                    $line .=  
     897                    '<span class="module-author">'.sprintf(__('by %s'),html::escapeHTML($module['author'])).'</span> '; 
     898               } 
     899 
     900               if (in_array('version', $cols)) { 
     901                    $line .=  
     902                    '<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> '; 
     903               } 
     904 
     905               if (in_array('parent', $cols) && $has_parent) { 
     906                    if ($is_parent_present) { 
     907                         $line .=  
     908                         '<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> '; 
     909                    } 
     910                    else { 
     911                         $line .=  
     912                         '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 
     913                    } 
     914               } 
     915 
     916               $line .=  
     917               '</p>'. 
     918               '</div>'; 
     919 
    865920               if (in_array('sshot', $cols)) { 
    866921                    # Screenshot from url 
     
    881936               } 
    882937 
    883                if (in_array('name', $cols)) { 
    884                     $line .=  
    885                     '<h4 class="module-name">'.html::escapeHTML($module['name']).'</h4>'; 
    886                } 
    887  
    888                $line .=  
    889                '<div class="module-infos">'. 
    890                '<p>'; 
    891  
    892                if (in_array('desc', $cols)) { 
    893                     $line .=  
    894                     '<span class="module-desc">'.html::escapeHTML($module['desc']).'</span> '; 
    895                } 
    896  
    897                if (in_array('author', $cols)) { 
    898                     $line .=  
    899                     '<span class="module-author">'.sprintf(__('by %s'),html::escapeHTML($module['author'])).'</span> '; 
    900                } 
    901  
    902                if (in_array('version', $cols)) { 
    903                     $line .=  
    904                     '<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> '; 
    905                } 
    906  
    907                if (in_array('parent', $cols) && $has_parent) { 
    908                     if ($is_parent_present) { 
    909                          $line .=  
    910                          '<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> '; 
    911                     } 
    912                     else { 
    913                          $line .=  
    914                          '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 
    915                     } 
    916                } 
    917  
    918                $line .=  
    919                '</p>'. 
    920                '</div>'; 
    921  
    922938               $line .=  
    923939               '<div class="modules-actions">'; 
    924940                
    925941               # _GET actions 
    926                $line .=  
    927                '<p>'; 
    928942 
    929943               if ($current && $has_css) { 
    930944                    $line .=  
    931                     '<a href="'.$theme_url.'/style.css" class="button">'.__('View stylesheet').'</a> '; 
     945                    '<p><a href="'.$theme_url.'/style.css" class="button">'.__('View stylesheet').'</a></p>'; 
    932946               } 
    933947               if ($current && $has_conf) { 
    934948                    $line .=  
    935                     '<a href="'.$this->getPageURL('module='.$id.'&conf=1', false).'" class="button">'.__('Configure theme').'</a> '; 
    936                } 
    937                $line .=  
    938                '</p>'; 
     949                    '<p><a href="'.$this->getPageURL('module='.$id.'&conf=1', false).'" class="button">'.__('Configure theme').'</a></p>'; 
     950               } 
    939951 
    940952               # Plugins actions 
     
    965977          '</div>'; 
    966978 
    967           if(!$count) { 
     979          if(!$count && $this->getSearchQuery() === null) { 
    968980               echo  
    969981               '<p class="message">'.__('No module matches your search.').'</p>'; 
    970982          } 
    971983     } 
     984 
     985     protected function displayOtherLineAction($id, $module, $actions) 
     986     { 
     987          $submits = array(); 
     988 
     989          $this->core->blog->settings->addNamespace('system'); 
     990          if ($id == $this->core->blog->settings->system->theme) { 
     991               return null; 
     992          } 
     993 
     994          # Select theme to use on curent blog 
     995          if (in_array('select', $actions) && $this->path_writable) { 
     996               $submits[] = '<input type="submit" name="select" value="'.__('Choose').'" />'; 
     997          } 
     998 
     999          return $submits; 
     1000     } 
     1001      
     1002     protected function executeOtherAction($prefix, dcModules $modules, dcRepository $repository) 
     1003     { 
     1004          # Select theme to use on curent blog 
     1005          if (!empty($_POST['module']) && !empty($_POST['select'])) { 
     1006               $id = $_POST['module']; 
     1007 
     1008               if (!$modules->moduleExists($id)) { 
     1009                    throw new Exception(__('No such module.')); 
     1010               } 
     1011 
     1012               $this->core->blog->settings->addNamespace('system'); 
     1013               $this->core->blog->settings->system->put('theme',$id); 
     1014               $this->core->blog->triggerBlog(); 
     1015 
     1016               http::redirect($this->getPageURL('msg=select').'#themes'); 
     1017          } 
     1018 
     1019          return null; 
     1020     } 
    9721021} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map