Changeset 2149:04a490b510cc
- Timestamp:
- 09/29/13 14:14:48 (11 years ago)
- Branch:
- dcRepo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/style/default.css
r2123 r2149 1968 1968 vertical-align: middle; 1969 1969 } 1970 .icon img { 1971 width: 16px; 1972 height: 16px; 1973 } 1970 1974 .distrib img { 1971 1975 display: block; 1972 1976 float: right; 1973 margin-top: -1em;1974 1977 } 1975 1978 /* ---------------------------------------------------------- post.php, page.php */ -
inc/admin/lib.moduleslist.php
r2148 r2149 6 6 public $modules; 7 7 8 protected $page_url = ''; 8 public static $allow_multi_install; 9 10 protected $path = false; 11 protected $path_writable = false; 12 protected $path_pattern = false; 13 14 protected $page_url = 'plugins.php'; 9 15 protected $page_qs = '?'; 10 16 protected $page_tab = ''; … … 17 23 protected $sort_asc = true; 18 24 19 public function __construct($core, $ modules, $page_url='', $page_tab='')25 public function __construct($core, $root, $allow_multi_install=false) 20 26 { 21 27 $this->core = $core; 22 $this->setModules($modules); 23 $this->setPageURL($page_url); 24 $this->setPageTab($page_tab); 28 self::$allow_multi_install = (boolean) $allow_multi_install; 29 $this->setPathInfo($root); 25 30 $this->setNavSpecial(__('other')); 26 31 … … 31 36 { 32 37 return null; 38 } 39 40 protected function setPathInfo($root) 41 { 42 $paths = explode(PATH_SEPARATOR, $root); 43 $path = array_pop($paths); 44 unset($paths); 45 46 $this->path = $path; 47 if (is_dir($path) && is_writeable($path)) { 48 $this->path_writable = true; 49 $this->path_pattern = preg_quote($path,'!'); 50 } 51 52 return $this; 53 } 54 55 public function getPath() 56 { 57 return $this->path; 58 } 59 60 public function isPathWritable() 61 { 62 return $this->path_writable; 63 } 64 65 public function isPathDeletable($root) 66 { 67 return $this->path_writable 68 && preg_match('!^'.$this->path_pattern.'!', $root) 69 && $this->core->auth->isSuperAdmin(); 33 70 } 34 71 … … 44 81 { 45 82 return $this->page_url. 46 ( $with_tab && !empty($this->page_tab) ||!empty($queries) ? $this->page_qs : '').83 (!empty($queries) ? $this->page_qs : ''). 47 84 (is_array($queries) ? http_build_query($queries) : $queries). 48 ($with_tab && !empty($this->page_tab) && !empty($queries) ? '&' : ''). 49 ($with_tab && !empty($this->page_tab) ? /*'tab='$this->page_tab.*/'#'.$this->page_tab : ''); 85 ($with_tab && !empty($this->page_tab) ? '#'.$this->page_tab : ''); 50 86 } 51 87 … … 173 209 { 174 210 //not yet implemented 211 } 212 213 public function displayMessage($action) 214 { 215 switch($action) { 216 case 'activate': 217 $str = __('Module successfully activated.'); break; 218 case 'deactivate': 219 $str = __('Module successfully deactivated.'); break; 220 case 'delete': 221 $str = __('Module successfully deleted.'); break; 222 case 'install': 223 $str = __('Module successfully installed.'); break; 224 case 'update': 225 $str = __('Module successfully updated.'); break; 226 default: 227 $str = ''; break; 228 } 229 if (!empty($str)) { 230 dcPage::success($str); 231 } 175 232 } 176 233 … … 261 318 '<div class="table-outer">'. 262 319 '<table class="modules"><caption class="hidden">'.html::escapeHTML(__('Modules list')).'</caption><tr>'; 263 320 /* 321 if ($this->getSearchQuery() !== null) { 322 echo 323 '<th class="nowrap">'.__('Accuracy').'</th>'; 324 } 325 //*/ 264 326 if (in_array('name', $cols)) { 265 327 echo 266 '<th class="first nowrap" >'.__('Name').'</th>';328 '<th class="first nowrap"'.(in_array('icon', $cols) ? ' colspan="2"' : '').'>'.__('Name').'</th>'; 267 329 } 268 330 … … 280 342 echo 281 343 '<th class="nowrap" scope="col">'.__('Details').'</th>'; 344 } 345 346 if (in_array('distrib', $cols)) { 347 echo '<th'.(in_array('desc', $cols) ? '' : ' class="maximal"').'></th>'; 282 348 } 283 349 … … 314 380 '<tr class="line" id="'.$this->getPageTab().'_p_'.html::escapeHTML($id).'">'; 315 381 382 if (in_array('icon', $cols)) { 383 echo 384 '<td class="nowrap icon">'.sprintf( 385 '<img alt="%1$s" title="%1$s" src="%2$s" />', 386 html::escapeHTML($id), file_exists($module['root'].'/icon.png') ? 'index.php?pf='.$id.'/icon.png' : 'images/favicon.png' 387 ).'</td>'; 388 } 389 /* 390 if ($this->getSearchQuery() !== null) { 391 echo 392 '<td class="nowrap count">'.$module['accuracy'].'</td>'; 393 } 394 //*/ 316 395 # Link to config file 317 396 $config = in_array('config', $cols) && !empty($module['root']) && file_exists(path::real($module['root'].'/_config.php')); … … 319 398 echo 320 399 '<td class="nowrap" scope="row">'.($config ? 321 '<a href="'.$this->getPageURL('module='.$id.'&conf=1').'">'.html::escapeHTML( __($module['name'])).'</a>' :322 html::escapeHTML( __($module['name']))400 '<a href="'.$this->getPageURL('module='.$id.'&conf=1').'">'.html::escapeHTML($module['name']).'</a>' : 401 html::escapeHTML($module['name']) 323 402 ).'</td>'; 324 403 … … 335 414 if (in_array('desc', $cols)) { 336 415 echo 337 '<td class="maximal">'.html::escapeHTML(__($module['desc'])).'</td>'; 416 '<td class="maximal">'.html::escapeHTML($module['desc']).'</td>'; 417 } 418 419 if (in_array('distrib', $cols)) { 420 echo 421 '<td class="distrib">'.(self::isDistributedModule($id) ? 422 '<img src="images/dotclear_pw.png" alt="'. 423 __('Module from official distribution').'" title="'. 424 __('module from official distribution').'" />' 425 : '').'</td>'; 338 426 } 339 427 … … 375 463 $submits[] = '<input type="submit" name="activate" value="'.__('Activate').'" />'; 376 464 } 377 /* 465 378 466 # Delete 379 if (in_array('delete', $actions) && $this->isPath Writable() && preg_match('!^'.$this->path_pattern.'!',$module['root'])) {467 if (in_array('delete', $actions) && $this->isPathDeletable($module['root'])) { 380 468 $submits[] = '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />'; 381 469 } 382 470 383 471 # Install (form repository) 384 if (in_array('install', $actions) && $this-> isPathWritable()) {472 if (in_array('install', $actions) && $this->path_writable) { 385 473 $submits[] = '<input type="submit" name="install" value="'.__('Install').'" />'; 386 474 } 387 475 388 476 # Update (from repository) 389 if (in_array('update', $actions) && $this-> isPathWritable()) {477 if (in_array('update', $actions) && $this->path_writable) { 390 478 $submits[] = '<input type="submit" name="update" value="'.__('Update').'" />'; 391 479 } 392 */ 480 393 481 # Parse form 394 482 if (!empty($submits)) { … … 398 486 $this->core->formNonce(). 399 487 form::hidden(array('module'), html::escapeHTML($id)). 400 form::hidden(array('tab'), $this-> getPageTab()).488 form::hidden(array('tab'), $this->page_tab). 401 489 implode(' ', $submits). 402 490 '</div>'. … … 405 493 } 406 494 495 public function executeAction($prefix, dcModules $modules, dcRepository $repository) 496 { 497 if (empty($_POST['module']) || !$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 498 return null; 499 } 500 501 $id = $_POST['module']; 502 503 if (!empty($_POST['activate'])) { 504 505 $enabled = $modules->getDisabledModules(); 506 if (!isset($enabled[$id])) { 507 throw new Exception(__('No such module.')); 508 } 509 510 # --BEHAVIOR-- moduleBeforeActivate 511 $this->core->callBehavior($type.'BeforeActivate', $id); 512 513 $modules->activateModule($id); 514 515 # --BEHAVIOR-- moduleAfterActivate 516 $this->core->callBehavior($type.'AfterActivate', $id); 517 518 http::redirect($this->getPageURL('msg=activate')); 519 } 520 521 if (!empty($_POST['deactivate'])) { 522 523 if (!$modules->moduleExists($id)) { 524 throw new Exception(__('No such module.')); 525 } 526 527 $module = $modules->getModules($id); 528 $module['id'] = $id; 529 530 if (!$module['root_writable']) { 531 throw new Exception(__('You don\'t have permissions to deactivate this module.')); 532 } 533 534 # --BEHAVIOR-- moduleBeforeDeactivate 535 $this->core->callBehavior($prefix.'BeforeDeactivate', $module); 536 537 $modules->deactivateModule($id); 538 539 # --BEHAVIOR-- moduleAfterDeactivate 540 $this->core->callBehavior($prefix.'AfterDeactivate', $module); 541 542 http::redirect($this->getPageURL('msg=deactivate')); 543 } 544 545 if (!empty($_POST['delete'])) { 546 547 $disabled = $modules->getDisabledModules(); 548 if (!isset($disabled[$id])) { 549 550 if (!$modules->moduleExists($id)) { 551 throw new Exception(__('No such module.')); 552 } 553 554 $module = $modules->getModules($id); 555 $module['id'] = $id; 556 557 if (!$this->isPathDeletable($module['root'])) { 558 throw new Exception(__("You don't have permissions to delete this module.")); 559 } 560 561 # --BEHAVIOR-- moduleBeforeDelete 562 $this->core->callBehavior($prefix.'BeforeDelete', $module); 563 564 $modules->deleteModule($id); 565 566 # --BEHAVIOR-- moduleAfterDelete 567 $this->core->callBehavior($prefix.'AfterDelete', $module); 568 } 569 else { 570 $modules->deleteModule($id, true); 571 } 572 573 http::redirect($this->getPageURL('msg=delete')); 574 } 575 576 if (!empty($_POST['update'])) { 577 578 $updated = $repository->get(); 579 if (!isset($updated[$id])) { 580 throw new Exception(__('No such module.')); 581 } 582 583 if (!$modules->moduleExists($id)) { 584 throw new Exception(__('No such module.')); 585 } 586 587 $module = $updated[$id]; 588 $module['id'] = $id; 589 590 if (!self::$allow_multi_install) { 591 $dest = $module['root'].'/../'.basename($module['file']); 592 } 593 else { 594 $dest = $this->getPath().'/'.basename($module['file']); 595 if ($module['root'] != $dest) { 596 @file_put_contents($module['root'].'/_disabled', ''); 597 } 598 } 599 600 # --BEHAVIOR-- moduleBeforeUpdate 601 $this->core->callBehavior($type.'BeforeUpdate', $module); 602 603 $repository->process($module['file'], $dest); 604 605 # --BEHAVIOR-- moduleAfterUpdate 606 $this->core->callBehavior($type.'AfterUpdate', $module); 607 608 http::redirect($this->getPageURL('msg=upadte')); 609 } 610 611 if (!empty($_POST['install'])) { 612 613 $updated = $repository->get(); 614 if (!isset($updated[$id])) { 615 throw new Exception(__('No such module.')); 616 } 617 618 $module = $updated[$id]; 619 $module['id'] = $id; 620 621 $dest = $this->getPath().'/'.basename($module['file']); 622 623 # --BEHAVIOR-- moduleBeforeAdd 624 $this->core->callBehavior($type.'BeforeAdd', $module); 625 626 $ret_code = $repository->process($module['file'], $dest); 627 628 # --BEHAVIOR-- moduleAfterAdd 629 $this->core->callBehavior($type.'AfterAdd', $module); 630 631 http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install'))); 632 } 633 } 634 407 635 public static function sanitizeString($str) 408 636 { -
inc/core/class.dc.repository.php
r2148 r2149 91 91 # Increment matches count 92 92 $sorter[$id] += $nb; 93 $result[$id]['accuracy'] = $sorter[$id]; 93 94 } 94 95 # Sort response by matches count … … 101 102 public function process($url, $dest) 102 103 { 104 $this->download($url, $dest); 105 return $this->install($dest); 106 } 107 108 public function download($url, $dest) 109 { 103 110 try { 104 111 $client = netHttp::initClient($url, $path); … … 108 115 $client->setOutput($dest); 109 116 $client->get($path); 117 unset($client); 110 118 } 111 119 catch (Exception $e) { 120 unset($client); 112 121 throw new Exception(__('An error occurred while downloading the file.')); 113 122 } 123 } 114 124 115 unset($client); 116 $ret_code = dcModules::installPackage($dest, $this->modules); 117 118 return $ret_code; 125 public function install($path) 126 { 127 return dcModules::installPackage($path, $this->modules); 119 128 } 120 129
Note: See TracChangeset
for help on using the changeset viewer.