Changeset 2215:0775c8672865 for inc/admin/lib.moduleslist.php
- Timestamp:
- 10/02/13 17:00:38 (12 years ago)
- Branch:
- dcRepo
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/lib.moduleslist.php
r2195 r2215 1 1 <?php 2 # -- BEGIN LICENSE BLOCK --------------------------------------- 3 # 4 # This file is part of Dotclear 2. 5 # 6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 7 # Licensed under the GPL version 2.0 license. 8 # See LICENSE file or 9 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 10 # 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_ADMIN_CONTEXT')) { return; } 2 13 3 14 class adminModulesList … … 5 16 public $core; 6 17 public $modules; 7 8 public static $allow_multi_install; 18 public $repository; 19 20 public static $allow_multi_install = false; 9 21 public static $distributed_modules = array(); 10 22 11 23 protected $list_id = 'unknow'; 24 protected $data = array(); 12 25 13 26 protected $config_module = ''; … … 30 43 protected $sort_asc = true; 31 44 32 public function __construct($core, $root, $allow_multi_install=false) 33 { 34 $this->core = $core; 35 self::$allow_multi_install = (boolean) $allow_multi_install; 36 $this->setPathInfo($root); 45 public function __construct(dcModules $modules, $modules_root, $xml_url) 46 { 47 $this->core = $modules->core; 48 $this->modules = $modules; 49 $this->repository = new dcRepository($modules, $xml_url); 50 51 $this->setPathInfo($modules_root); 37 52 $this->setNavSpecial(__('other')); 38 39 $this->init();40 }41 42 protected function init()43 {44 return null;45 53 } 46 54 47 55 public function newList($list_id) 48 56 { 49 $this-> modules= array();57 $this->data = array(); 50 58 $this->page_tab = ''; 51 59 $this->list_id = $list_id; … … 124 132 $query = $this->getSearchQuery(); 125 133 126 if (empty($this-> modules) && $query === null) {134 if (empty($this->data) && $query === null) { 127 135 return $this; 128 136 } … … 140 148 echo 141 149 '<p class="message">'.sprintf( 142 __('Found %d result for search "%s":', 'Found %d results for search "%s":', count($this-> modules)),143 count($this-> modules), html::escapeHTML($query)150 __('Found %d result for search "%s":', 'Found %d results for search "%s":', count($this->data)), 151 count($this->data), html::escapeHTML($query) 144 152 ). 145 153 '</p>'; … … 163 171 public function displayNavMenu() 164 172 { 165 if (empty($this-> modules) || $this->getSearchQuery() !== null) {173 if (empty($this->data) || $this->getSearchQuery() !== null) { 166 174 return $this; 167 175 } … … 169 177 # Fetch modules required field 170 178 $indexes = array(); 171 foreach ($this-> modulesas $id => $module) {179 foreach ($this->data as $id => $module) { 172 180 if (!isset($module[$this->sort_field])) { 173 181 continue; … … 246 254 public function setModules($modules) 247 255 { 248 $this-> modules= array();256 $this->data = array(); 249 257 if (!empty($modules) && is_array($modules)) { 250 258 foreach($modules as $id => $module) { 251 $this-> modules[$id] = self::parseModuleInfo($id, $module);259 $this->data[$id] = self::parseModuleInfo($id, $module); 252 260 } 253 261 } … … 257 265 public function getModules() 258 266 { 259 return $this-> modules;267 return $this->data; 260 268 } 261 269 … … 297 305 } 298 306 299 public static function setDistributedModules($modules)300 {301 self::$distributed_modules = $modules;302 }303 304 307 public static function isDistributedModule($module) 305 308 { … … 361 364 $sort_field = $this->getSortQuery(); 362 365 363 # Sort modules by id366 # Sort modules by $sort_field (default sname) 364 367 $modules = $this->getSearchQuery() === null ? 365 self::sortModules($this-> modules, $sort_field, $this->sort_asc) :366 $this-> modules;368 self::sortModules($this->data, $sort_field, $this->sort_asc) : 369 $this->data; 367 370 368 371 $count = 0; … … 425 428 426 429 if (!empty($actions) && $this->core->auth->isSuperAdmin()) { 430 $buttons = $this->getActions($id, $module, $actions); 431 427 432 echo 428 '<td class="module-actions nowrap">'; 429 430 $this->displayLineActions($id, $module, $actions); 431 432 echo 433 '<td class="module-actions nowrap">'. 434 435 '<form action="'.$this->getPageURL().'" method="post">'. 436 '<div>'. 437 $this->core->formNonce(). 438 form::hidden(array('module'), html::escapeHTML($id)). 439 form::hidden(array('tab'), $this->page_tab). 440 441 implode(' ', $buttons). 442 443 '</div>'. 444 '</form>'. 445 433 446 '</td>'; 434 447 } … … 448 461 } 449 462 450 protected function displayLineActions($id, $module, $actions, $echo=true)463 protected function getActions($id, $module, $actions) 451 464 { 452 465 $submits = array(); 453 466 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 } 468 469 # Activate 470 if (in_array('deactivate', $actions) && $module['root_writable']) { 471 $submits[] = '<input type="submit" name="deactivate" value="'.__('Deactivate').'" class="reset" />'; 472 } 473 474 # Deactivate 475 if (in_array('activate', $actions) && $module['root_writable']) { 476 $submits[] = '<input type="submit" name="activate" value="'.__('Activate').'" />'; 477 } 478 479 # Delete 480 if (in_array('delete', $actions) && $this->isPathDeletable($module['root'])) { 481 $submits[] = '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; 482 } 483 484 # Parse form 485 if (!empty($submits)) { 486 $res = 487 '<form action="'.$this->getPageURL().'" method="post">'. 488 '<div>'. 489 $this->core->formNonce(). 490 form::hidden(array('module'), html::escapeHTML($id)). 491 form::hidden(array('tab'), $this->page_tab). 492 implode(' ', $submits). 493 '</div>'. 494 '</form>'; 495 496 if (!$echo) { 497 return $res; 498 } 499 echo $res; 500 } 501 } 502 503 protected function displayOtherLineAction($id, $module, $actions) 504 { 505 return null; 506 } 507 508 public function executeAction($prefix, dcModules $modules, dcRepository $repository) 509 { 510 if (!$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 467 # Use loop to keep requested order 468 foreach($actions as $action) { 469 switch($action) { 470 471 # Deactivate 472 case 'activate': if ($module['root_writable']) { 473 $submits[] = 474 '<input type="submit" name="activate" value="'.__('Activate').'" />'; 475 } break; 476 477 # Activate 478 case 'deactivate': if ($module['root_writable']) { 479 $submits[] = 480 '<input type="submit" name="deactivate" value="'.__('Deactivate').'" class="reset" />'; 481 } break; 482 483 # Delete 484 case 'delete': if ($this->isPathDeletable($module['root'])) { 485 $submits[] = 486 '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; 487 } break; 488 489 # Install (from repository) 490 case 'install': if ($this->path_writable) { 491 $submits[] = 492 '<input type="submit" name="install" value="'.__('Install').'" />'; 493 } break; 494 495 # Update (from repository) 496 case 'update': if ($this->path_writable) { 497 $submits[] = 498 '<input type="submit" name="update" value="'.__('Update').'" />'; 499 } break; 500 } 501 } 502 503 return $submits; 504 } 505 506 public function doActions($prefix) 507 { 508 if (empty($_POST) || !empty($_REQUEST['conf']) 509 || !$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 511 510 return null; 512 511 } … … 519 518 if (!empty($_POST['activate'])) { 520 519 521 $enabled = $ modules->getDisabledModules();520 $enabled = $this->modules->getDisabledModules(); 522 521 if (!isset($enabled[$id])) { 523 522 throw new Exception(__('No such module.')); … … 527 526 $this->core->callBehavior($prefix.'BeforeActivate', $id); 528 527 529 $ modules->activateModule($id);528 $this->modules->activateModule($id); 530 529 531 530 # --BEHAVIOR-- moduleAfterActivate … … 537 536 elseif (!empty($_POST['deactivate'])) { 538 537 539 if (!$ modules->moduleExists($id)) {538 if (!$this->modules->moduleExists($id)) { 540 539 throw new Exception(__('No such module.')); 541 540 } 542 541 543 $module = $ modules->getModules($id);542 $module = $this->modules->getModules($id); 544 543 $module['id'] = $id; 545 544 … … 551 550 $this->core->callBehavior($prefix.'BeforeDeactivate', $module); 552 551 553 $ modules->deactivateModule($id);552 $this->modules->deactivateModule($id); 554 553 555 554 # --BEHAVIOR-- moduleAfterDeactivate … … 561 560 elseif (!empty($_POST['delete'])) { 562 561 563 $disabled = $ modules->getDisabledModules();562 $disabled = $this->modules->getDisabledModules(); 564 563 if (!isset($disabled[$id])) { 565 564 566 if (!$ modules->moduleExists($id)) {565 if (!$this->modules->moduleExists($id)) { 567 566 throw new Exception(__('No such module.')); 568 567 } 569 568 570 $module = $ modules->getModules($id);569 $module = $this->modules->getModules($id); 571 570 $module['id'] = $id; 572 571 … … 578 577 $this->core->callBehavior($prefix.'BeforeDelete', $module); 579 578 580 $ modules->deleteModule($id);579 $this->modules->deleteModule($id); 581 580 582 581 # --BEHAVIOR-- moduleAfterDelete … … 584 583 } 585 584 else { 586 $ modules->deleteModule($id, true);585 $this->modules->deleteModule($id, true); 587 586 } 588 587 589 588 http::redirect($this->getPageURL('msg=delete')); 589 } 590 591 elseif (!empty($_POST['install'])) { 592 593 $updated = $this->repository->get(); 594 if (!isset($updated[$id])) { 595 throw new Exception(__('No such module.')); 596 } 597 598 $module = $updated[$id]; 599 $module['id'] = $id; 600 601 $dest = $this->getPath().'/'.basename($module['file']); 602 603 # --BEHAVIOR-- moduleBeforeAdd 604 $this->core->callBehavior($prefix.'BeforeAdd', $module); 605 606 $ret_code = $this->repository->process($module['file'], $dest); 607 608 # --BEHAVIOR-- moduleAfterAdd 609 $this->core->callBehavior($prefix.'AfterAdd', $module); 610 611 http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install'))); 590 612 } 591 613 … … 597 619 } 598 620 599 if (!$ modules->moduleExists($id)) {621 if (!$this->modules->moduleExists($id)) { 600 622 throw new Exception(__('No such module.')); 601 623 } … … 617 639 $this->core->callBehavior($prefix.'BeforeUpdate', $module); 618 640 619 $ repository->process($module['file'], $dest);641 $this->repository->process($module['file'], $dest); 620 642 621 643 # --BEHAVIOR-- moduleAfterUpdate … … 623 645 624 646 http::redirect($this->getPageURL('msg=upadte')); 625 }626 627 elseif (!empty($_POST['install'])) {628 629 $updated = $repository->get();630 if (!isset($updated[$id])) {631 throw new Exception(__('No such module.'));632 }633 634 $module = $updated[$id];635 $module['id'] = $id;636 637 $dest = $this->getPath().'/'.basename($module['file']);638 639 # --BEHAVIOR-- moduleBeforeAdd640 $this->core->callBehavior($prefix.'BeforeAdd', $module);641 642 $ret_code = $repository->process($module['file'], $dest);643 644 # --BEHAVIOR-- moduleAfterAdd645 $this->core->callBehavior($prefix.'AfterAdd', $module);646 647 http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install')));648 647 } 649 648 } … … 667 666 $url = urldecode($_POST['pkg_url']); 668 667 $dest = $this->getPath().'/'.basename($url); 669 $ repository->download($url, $dest);668 $this->repository->download($url, $dest); 670 669 } 671 670 … … 673 672 $this->core->callBehavior($prefix.'BeforeAdd', null); 674 673 675 $ret_code = $ repository->install($dest);674 $ret_code = $this->repository->install($dest); 676 675 677 676 # --BEHAVIOR-- moduleAfterAdd … … 681 680 } 682 681 683 return $this->executeOtherAction($prefix, $modules, $repository);684 }685 686 /**687 *688 * Way for child class to execute their own actions689 * whitout rewriting all standard actions.690 */691 protected function executeOtherAction($prefix, dcModules $modules, dcRepository $repository)692 {693 682 return null; 694 683 } … … 740 729 * 741 730 */ 742 public function setConfigurationFile( dcModules $modules,$id=null)731 public function setConfigurationFile($id=null) 743 732 { 744 733 if (empty($_REQUEST['conf']) || empty($_REQUEST['module']) && !$id) { … … 750 739 } 751 740 752 if (!$ modules->moduleExists($id)) {741 if (!$this->modules->moduleExists($id)) { 753 742 $core->error->add(__('Unknow module ID')); 754 743 return false; 755 744 } 756 745 757 $module = $ modules->getModules($id);746 $module = $this->modules->getModules($id); 758 747 $module = self::parseModuleInfo($id, $module); 759 748 $file = path::real($module['root'].'/_config.php'); … … 842 831 # Sort modules by id 843 832 $modules = $this->getSearchQuery() === null ? 844 self::sortModules($this-> modules, $sort_field, $this->sort_asc) :845 $this-> modules;833 self::sortModules($this->data, $sort_field, $this->sort_asc) : 834 $this->data; 846 835 847 836 $res = ''; … … 861 850 862 851 $current = $this->core->blog->settings->system->theme == $id; 863 864 if (preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url)) { 865 $theme_url = http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id); 866 } else { 867 $theme_url = http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id); 868 } 852 $distrib = self::isDistributedModule($id) ? ' dc-box' : ''; 853 854 $theme_url = preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url) ? 855 http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id) : 856 http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id); 869 857 870 858 $has_conf = file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/_config.php'); … … 877 865 878 866 $line = 879 '<div class="box '.($current ? 'medium current-theme' : 'small theme'). '">';867 '<div class="box '.($current ? 'medium current-theme' : 'small theme').$distrib.'">'; 880 868 881 869 if (in_array('name', $cols)) { … … 899 887 900 888 $line .= 901 '<div class="module-sshot"><img src="'.$sshot.'" alt="'.__('screenshot.').'" /></div>'; 889 '<div class="module-sshot"><img src="'.$sshot.'" alt="'. 890 sprintf(__('%s screenshot.'), html::escapeHTML($module['name'])).'" /></div>'; 902 891 } 903 892 … … 930 919 '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 931 920 } 921 } 922 923 if (in_array('version', $cols)) { 924 $line .= 925 '<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> '; 926 } 927 928 $has_details = in_array('details', $cols) && !empty($module['details']); 929 $has_support = in_array('support', $cols) && !empty($module['support']); 930 if ($has_details || $has_support) { 931 $line .= 932 '<span class="mod-more">'.__('Help:').' '; 933 934 if ($has_details) { 935 $line .= 936 '<a class="module-details" href="'.$module['details'].'">'.__('Details').'</a>'; 937 } 938 939 if ($has_support) { 940 $line .= 941 ' - <a class="module-support" href="'.$module['support'].'">'.__('Support').'</a>'; 942 } 943 944 $line .= 945 '</span>'; 932 946 } 933 947 … … 958 972 959 973 # _POST actions 960 if (!empty($actions) && $this->core->auth->isSuperAdmin()) {974 if (!empty($actions)) { 961 975 $line .= 962 $this->displayLineActions($id, $module, $actions, false); 976 '<form action="'.$this->getPageURL().'" method="post">'. 977 '<div>'. 978 $this->core->formNonce(). 979 form::hidden(array('module'), html::escapeHTML($id)). 980 form::hidden(array('tab'), $this->page_tab). 981 982 implode(' ', $this->getActions($id, $module, $actions)). 983 984 '</div>'. 985 '</form>'; 963 986 } 964 987 … … 983 1006 } 984 1007 985 protected function displayOtherLineAction($id, $module, $actions)1008 protected function getActions($id, $module, $actions) 986 1009 { 987 1010 $submits = array(); 988 1011 989 1012 $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; 1013 if ($id != $this->core->blog->settings->system->theme) { 1014 1015 # Select theme to use on curent blog 1016 if (in_array('select', $actions) && $this->path_writable) { 1017 $submits[] = '<input type="submit" name="select" value="'.__('Choose').'" />'; 1018 } 1019 } 1020 1021 return array_merge( 1022 $submits, 1023 parent::getActions($id, $module, $actions) 1024 ); 1025 } 1026 1027 public function doActions($prefix) 1028 { 1029 if (!empty($_POST) && empty($_REQUEST['conf']) && $this->isPathWritable()) { 1030 1031 # Select theme to use on curent blog 1032 if (!empty($_POST['module']) && !empty($_POST['select'])) { 1033 $id = $_POST['module']; 1034 1035 if (!$this->modules->moduleExists($id)) { 1036 throw new Exception(__('No such module.')); 1037 } 1038 1039 $this->core->blog->settings->addNamespace('system'); 1040 $this->core->blog->settings->system->put('theme',$id); 1041 $this->core->blog->triggerBlog(); 1042 1043 http::redirect($this->getPageURL('msg=select').'#themes'); 1044 } 1045 } 1046 1047 return parent::doActions($prefix); 1020 1048 } 1021 1049 }
Note: See TracChangeset
for help on using the changeset viewer.