Changeset 2171:bb80994ddeed for inc/admin/lib.moduleslist.php
- Timestamp:
- 09/30/13 18:03:03 (12 years ago)
- Branch:
- dcRepo
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/lib.moduleslist.php
r2163 r2171 7 7 8 8 public static $allow_multi_install; 9 public static $distributed_modules = array(); 9 10 10 11 protected $list_id = 'unknow'; … … 275 276 'section' => '', 276 277 'tags' => '', 277 'details' => '' 278 'details' => '', 279 'sshot' => '' 278 280 ), 279 281 # Module's values … … 290 292 } 291 293 294 public static function setDistributedModules($modules) 295 { 296 self::$distributed_modules = $modules; 297 } 298 292 299 public static function isDistributedModule($module) 293 300 { 294 return in_array($module, array( 295 'aboutConfig', 296 'akismet', 297 'antispam', 298 'attachments', 299 'blogroll', 300 'blowupConfig', 301 'daInstaller', 302 'fairTrackbacks', 303 'importExport', 304 'maintenance', 305 'pages', 306 'pings', 307 'simpleMenu', 308 'tags', 309 'themeEditor', 310 'userPref', 311 'widgets' 312 )); 301 $distributed_modules = self::$distributed_modules; 302 303 return is_array($distributed_modules) && in_array($module, $distributed_modules); 313 304 } 314 305 … … 385 376 386 377 echo 387 '<tr class="line" id="'.html::escapeHTML($this->list_id).'_m_'.html::escapeHTML($id).'" title="'. 388 sprintf(__('Configure module "%"'), html::escapeHTML($module['name'])).'">'; 378 '<tr class="line" id="'.html::escapeHTML($this->list_id).'_m_'.html::escapeHTML($id).'">'; 389 379 390 380 if (in_array('icon', $cols)) { 391 381 echo 392 '<td class=" nowrap icon">'.sprintf(382 '<td class="module-icon nowrap">'.sprintf( 393 383 '<img alt="%1$s" title="%1$s" src="%2$s" />', 394 384 html::escapeHTML($id), file_exists($module['root'].'/icon.png') ? 'index.php?pf='.$id.'/icon.png' : 'images/module.png' … … 400 390 401 391 echo 402 '<td class=" nowrap" scope="row">'.($config ?403 '<a href="'.$this->getPageURL('module='.$id.'&conf=1').'" >'.html::escapeHTML($module['name']).'</a>' :392 '<td class="module-name nowrap" scope="row">'.($config ? 393 '<a href="'.$this->getPageURL('module='.$id.'&conf=1').'" title"'.sprintf(__('Configure module "%s"'), html::escapeHTML($module['name'])).'">'.html::escapeHTML($module['name']).'</a>' : 404 394 html::escapeHTML($module['name']) 405 395 ).'</td>'; … … 407 397 if (in_array('version', $cols)) { 408 398 echo 409 '<td class=" nowrap count">'.html::escapeHTML($module['version']).'</td>';399 '<td class="module-version nowrap count">'.html::escapeHTML($module['version']).'</td>'; 410 400 } 411 401 412 402 if (in_array('current_version', $cols)) { 413 403 echo 414 '<td class=" nowrap count">'.html::escapeHTML($module['current_version']).'</td>';404 '<td class="module-current-version nowrap count">'.html::escapeHTML($module['current_version']).'</td>'; 415 405 } 416 406 417 407 if (in_array('desc', $cols)) { 418 408 echo 419 '<td class="m aximal">'.html::escapeHTML($module['desc']).'</td>';409 '<td class="module-desc maximal">'.html::escapeHTML($module['desc']).'</td>'; 420 410 } 421 411 422 412 if (in_array('distrib', $cols)) { 423 413 echo 424 '<td class=" distrib">'.(self::isDistributedModule($id) ?414 '<td class="module-distrib">'.(self::isDistributedModule($id) ? 425 415 '<img src="images/dotclear_pw.png" alt="'. 426 416 __('Module from official distribution').'" title="'. … … 431 421 if (!empty($actions) && $this->core->auth->isSuperAdmin()) { 432 422 echo 433 '<td class=" nowrap">';423 '<td class="module-actions nowrap">'; 434 424 435 425 $this->displayLineActions($id, $module, $actions); … … 453 443 } 454 444 455 protected function displayLineActions($id, $module, $actions )445 protected function displayLineActions($id, $module, $actions, $echo=true) 456 446 { 457 447 $submits = array(); … … 484 474 # Parse form 485 475 if (!empty($submits)) { 486 echo476 $res = 487 477 '<form action="'.$this->getPageURL().'" method="post">'. 488 478 '<div>'. … … 493 483 '</div>'. 494 484 '</form>'; 485 486 if (!$echo) { 487 return $res; 488 } 489 echo $res; 495 490 } 496 491 } … … 498 493 public function executeAction($prefix, dcModules $modules, dcRepository $repository) 499 494 { 500 if ( empty($_POST['module']) ||!$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) {495 if (!$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 501 496 return null; 502 497 } 503 498 504 $id = $_POST['module']; 505 506 if (!empty($_POST['activate'])) { 507 508 $enabled = $modules->getDisabledModules(); 509 if (!isset($enabled[$id])) { 510 throw new Exception(__('No such module.')); 511 } 512 513 # --BEHAVIOR-- moduleBeforeActivate 514 $this->core->callBehavior($type.'BeforeActivate', $id); 515 516 $modules->activateModule($id); 517 518 # --BEHAVIOR-- moduleAfterActivate 519 $this->core->callBehavior($type.'AfterActivate', $id); 520 521 http::redirect($this->getPageURL('msg=activate')); 522 } 523 524 if (!empty($_POST['deactivate'])) { 525 526 if (!$modules->moduleExists($id)) { 527 throw new Exception(__('No such module.')); 528 } 529 530 $module = $modules->getModules($id); 531 $module['id'] = $id; 532 533 if (!$module['root_writable']) { 534 throw new Exception(__('You don\'t have permissions to deactivate this module.')); 535 } 536 537 # --BEHAVIOR-- moduleBeforeDeactivate 538 $this->core->callBehavior($prefix.'BeforeDeactivate', $module); 539 540 $modules->deactivateModule($id); 541 542 # --BEHAVIOR-- moduleAfterDeactivate 543 $this->core->callBehavior($prefix.'AfterDeactivate', $module); 544 545 http::redirect($this->getPageURL('msg=deactivate')); 546 } 547 548 if (!empty($_POST['delete'])) { 549 550 $disabled = $modules->getDisabledModules(); 551 if (!isset($disabled[$id])) { 499 # List actions 500 if (!empty($_POST['module'])) { 501 502 $id = $_POST['module']; 503 504 if (!empty($_POST['activate'])) { 505 506 $enabled = $modules->getDisabledModules(); 507 if (!isset($enabled[$id])) { 508 throw new Exception(__('No such module.')); 509 } 510 511 # --BEHAVIOR-- moduleBeforeActivate 512 $this->core->callBehavior($type.'BeforeActivate', $id); 513 514 $modules->activateModule($id); 515 516 # --BEHAVIOR-- moduleAfterActivate 517 $this->core->callBehavior($type.'AfterActivate', $id); 518 519 http::redirect($this->getPageURL('msg=activate')); 520 } 521 522 if (!empty($_POST['deactivate'])) { 552 523 553 524 if (!$modules->moduleExists($id)) { … … 558 529 $module['id'] = $id; 559 530 560 if (!$this->isPathDeletable($module['root'])) { 561 throw new Exception(__("You don't have permissions to delete this module.")); 562 } 563 564 # --BEHAVIOR-- moduleBeforeDelete 565 $this->core->callBehavior($prefix.'BeforeDelete', $module); 566 567 $modules->deleteModule($id); 568 569 # --BEHAVIOR-- moduleAfterDelete 570 $this->core->callBehavior($prefix.'AfterDelete', $module); 531 if (!$module['root_writable']) { 532 throw new Exception(__('You don\'t have permissions to deactivate this module.')); 533 } 534 535 # --BEHAVIOR-- moduleBeforeDeactivate 536 $this->core->callBehavior($prefix.'BeforeDeactivate', $module); 537 538 $modules->deactivateModule($id); 539 540 # --BEHAVIOR-- moduleAfterDeactivate 541 $this->core->callBehavior($prefix.'AfterDeactivate', $module); 542 543 http::redirect($this->getPageURL('msg=deactivate')); 544 } 545 546 if (!empty($_POST['delete'])) { 547 548 $disabled = $modules->getDisabledModules(); 549 if (!isset($disabled[$id])) { 550 551 if (!$modules->moduleExists($id)) { 552 throw new Exception(__('No such module.')); 553 } 554 555 $module = $modules->getModules($id); 556 $module['id'] = $id; 557 558 if (!$this->isPathDeletable($module['root'])) { 559 throw new Exception(__("You don't have permissions to delete this module.")); 560 } 561 562 # --BEHAVIOR-- moduleBeforeDelete 563 $this->core->callBehavior($prefix.'BeforeDelete', $module); 564 565 $modules->deleteModule($id); 566 567 # --BEHAVIOR-- moduleAfterDelete 568 $this->core->callBehavior($prefix.'AfterDelete', $module); 569 } 570 else { 571 $modules->deleteModule($id, true); 572 } 573 574 http::redirect($this->getPageURL('msg=delete')); 575 } 576 577 if (!empty($_POST['update'])) { 578 579 $updated = $repository->get(); 580 if (!isset($updated[$id])) { 581 throw new Exception(__('No such module.')); 582 } 583 584 if (!$modules->moduleExists($id)) { 585 throw new Exception(__('No such module.')); 586 } 587 588 $module = $updated[$id]; 589 $module['id'] = $id; 590 591 if (!self::$allow_multi_install) { 592 $dest = $module['root'].'/../'.basename($module['file']); 593 } 594 else { 595 $dest = $this->getPath().'/'.basename($module['file']); 596 if ($module['root'] != $dest) { 597 @file_put_contents($module['root'].'/_disabled', ''); 598 } 599 } 600 601 # --BEHAVIOR-- moduleBeforeUpdate 602 $this->core->callBehavior($type.'BeforeUpdate', $module); 603 604 $repository->process($module['file'], $dest); 605 606 # --BEHAVIOR-- moduleAfterUpdate 607 $this->core->callBehavior($type.'AfterUpdate', $module); 608 609 http::redirect($this->getPageURL('msg=upadte')); 610 } 611 612 if (!empty($_POST['install'])) { 613 614 $updated = $repository->get(); 615 if (!isset($updated[$id])) { 616 throw new Exception(__('No such module.')); 617 } 618 619 $module = $updated[$id]; 620 $module['id'] = $id; 621 622 $dest = $this->getPath().'/'.basename($module['file']); 623 624 # --BEHAVIOR-- moduleBeforeAdd 625 $this->core->callBehavior($type.'BeforeAdd', $module); 626 627 $ret_code = $repository->process($module['file'], $dest); 628 629 # --BEHAVIOR-- moduleAfterAdd 630 $this->core->callBehavior($type.'AfterAdd', $module); 631 632 http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install'))); 633 } 634 } 635 # Manual actions 636 elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file']) 637 || !empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])) 638 { 639 if (empty($_POST['your_pwd']) || !$this->core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY, $_POST['your_pwd']))) { 640 throw new Exception(__('Password verification failed')); 641 } 642 643 if (!empty($_POST['upload_pkg'])) { 644 files::uploadStatus($_FILES['pkg_file']); 645 646 $dest = $this->getPath().'/'.$_FILES['pkg_file']['name']; 647 if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) { 648 throw new Exception(__('Unable to move uploaded file.')); 649 } 571 650 } 572 651 else { 573 $modules->deleteModule($id, true); 574 } 575 576 http::redirect($this->getPageURL('msg=delete')); 577 } 578 579 if (!empty($_POST['update'])) { 580 581 $updated = $repository->get(); 582 if (!isset($updated[$id])) { 583 throw new Exception(__('No such module.')); 584 } 585 586 if (!$modules->moduleExists($id)) { 587 throw new Exception(__('No such module.')); 588 } 589 590 $module = $updated[$id]; 591 $module['id'] = $id; 652 $url = urldecode($_POST['pkg_url']); 653 $dest = $this->getPath().'/'.basename($url); 654 $repository->download($url, $dest); 655 } 656 657 # --BEHAVIOR-- moduleBeforeAdd 658 $this->core->callBehavior($prefix.'BeforeAdd', null); 659 660 $ret_code = $repository->install($dest); 661 662 # --BEHAVIOR-- moduleAfterAdd 663 $this->core->callBehavior($prefix.'AfterAdd', null); 664 665 http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install')).'#'.$prefix); 666 } 667 return null; 668 } 669 670 public function displayManualForm() 671 { 672 if (!$this->core->auth->isSuperAdmin() || !$this->isPathWritable()) { 673 return null; 674 } 675 676 # 'Upload module' form 677 echo 678 '<form method="post" action="'.$this->getPageURL().'" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. 679 '<h4>'.__('Upload a zip file').'</h4>'. 680 '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file path:').'</label> '. 681 '<input type="file" name="pkg_file" id="pkg_file" /></p>'. 682 '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 683 form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. 684 '<p><input type="submit" name="upload_pkg" value="'.__('Upload').'" />'. 685 form::hidden(array('tab'), $this->getPageTab()). 686 $this->core->formNonce().'</p>'. 687 '</form>'; 592 688 593 if (!self::$allow_multi_install) { 594 $dest = $module['root'].'/../'.basename($module['file']); 595 } 596 else { 597 $dest = $this->getPath().'/'.basename($module['file']); 598 if ($module['root'] != $dest) { 599 @file_put_contents($module['root'].'/_disabled', ''); 600 } 601 } 602 603 # --BEHAVIOR-- moduleBeforeUpdate 604 $this->core->callBehavior($type.'BeforeUpdate', $module); 605 606 $repository->process($module['file'], $dest); 607 608 # --BEHAVIOR-- moduleAfterUpdate 609 $this->core->callBehavior($type.'AfterUpdate', $module); 610 611 http::redirect($this->getPageURL('msg=upadte')); 612 } 613 614 if (!empty($_POST['install'])) { 615 616 $updated = $repository->get(); 617 if (!isset($updated[$id])) { 618 throw new Exception(__('No such module.')); 619 } 620 621 $module = $updated[$id]; 622 $module['id'] = $id; 623 624 $dest = $this->getPath().'/'.basename($module['file']); 625 626 # --BEHAVIOR-- moduleBeforeAdd 627 $this->core->callBehavior($type.'BeforeAdd', $module); 628 629 $ret_code = $repository->process($module['file'], $dest); 630 631 # --BEHAVIOR-- moduleAfterAdd 632 $this->core->callBehavior($type.'AfterAdd', $module); 633 634 http::redirect($this->getPageURL('msg='.($ret_code == 2 ? 'update' : 'install'))); 635 } 689 # 'Fetch module' form 690 echo 691 '<form method="post" action="'.$this->getPageURL().'" id="fetchpkg" class="fieldset">'. 692 '<h4>'.__('Download a zip file').'</h4>'. 693 '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file URL:').'</label> '. 694 form::field(array('pkg_url','pkg_url'),40,255).'</p>'. 695 '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 696 form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. 697 '<p><input type="submit" name="fetch_pkg" value="'.__('Download').'" />'. 698 form::hidden(array('tab'), $this->getPageTab()). 699 $this->core->formNonce().'</p>'. 700 '</form>'; 636 701 } 637 702 … … 644 709 class adminThemesList extends adminModulesList 645 710 { 646 711 protected $page_url = 'blog_theme.php'; 712 713 public function displayModulesList($cols=array('name', 'config', 'version', 'desc'), $actions=array(), $nav_limit=false) 714 { 715 echo 716 '<div id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').' one-box">'; 717 718 $sort_field = $this->getSortQuery(); 719 720 # Sort modules by id 721 $modules = $this->getSearchQuery() === null ? 722 self::sortModules($this->modules, $sort_field, $this->sort_asc) : 723 $this->modules; 724 725 $res = ''; 726 $count = 0; 727 foreach ($modules as $id => $module) 728 { 729 # Show only requested modules 730 if ($nav_limit && $this->getSearchQuery() === null) { 731 $char = substr($module[$sort_field], 0, 1); 732 if (!in_array($char, $this->nav_list)) { 733 $char = $this->nav_special; 734 } 735 if ($this->getNavQuery() != $char) { 736 continue; 737 } 738 } 739 740 $current = $this->core->blog->settings->system->theme == $id; 741 742 if (preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url)) { 743 $theme_url = http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id); 744 } else { 745 $theme_url = http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id); 746 } 747 748 $has_conf = file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/_config.php'); 749 $has_css = file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/style.css'); 750 $parent = $module['parent']; 751 $has_parent = !empty($module['parent']); 752 if ($has_parent) { 753 $is_parent_present = $this->core->themes->moduleExists($parent); 754 } 755 756 $line = 757 '<div class="box '.($current ? 'current-theme' : 'theme').'">'; 758 759 if (in_array('sshot', $cols)) { 760 # Screenshot from url 761 if (preg_match('#^http(s)?://#', $module['sshot'])) { 762 $sshot = $module['sshot']; 763 } 764 # Screenshot from installed module 765 elseif (file_exists($this->core->blog->themes_path.'/'.$id.'/screenshot.jpg')) { 766 $sshot = $this->getPageURL('shot='.rawurlencode($id)); 767 } 768 # Default screenshot 769 else { 770 $sshot = 'images/noscreenshot.png'; 771 } 772 773 $line .= 774 '<div class="module-sshot"><img src="'.$sshot.'" alt="'.__('screenshot.').'" /></div>'; 775 } 776 777 if (in_array('name', $cols)) { 778 $line .= 779 '<h4 class="module-name">'.html::escapeHTML($module['name']).'</h4>'; 780 } 781 782 $line .= 783 '<div class="module-infos">'. 784 '<p>'; 785 786 if (in_array('desc', $cols)) { 787 $line .= 788 '<span class="module-desc">'.html::escapeHTML($module['desc']).'</span> '; 789 } 790 791 if (in_array('author', $cols)) { 792 $line .= 793 '<span class="module-author">'.sprintf(__('by %s'),html::escapeHTML($module['author'])).'</span> '; 794 } 795 796 if (in_array('version', $cols)) { 797 $line .= 798 '<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> '; 799 } 800 801 if (in_array('parent', $cols) && $has_parent) { 802 if ($is_parent_present) { 803 $line .= 804 '<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> '; 805 } 806 else { 807 $line .= 808 '<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 809 } 810 } 811 812 $line .= 813 '</p>'. 814 '</div>'; 815 816 $line .= 817 '<div class="modules-actions">'; 818 819 # _GET actions 820 $line .= 821 '<p>'; 822 823 if ($current && $has_css) { 824 $line .= 825 '<a href="'.$theme_url.'/style.css" class="button">'.__('View stylesheet').'</a> '; 826 } 827 if ($current && $has_conf) { 828 $line .= 829 '<a href="'.$this->getPageURL('conf=1').'" class="button">'.__('Configure theme').'</a> '; 830 } 831 $line .= 832 '</p>'; 833 834 # Plugins actions 835 if ($current) { 836 # --BEHAVIOR-- adminCurrentThemeDetails 837 $line .= 838 $this->core->callBehavior('adminCurrentThemeDetails', $this->core, $id, $module); 839 } 840 841 # _POST actions 842 if (!empty($actions) && $this->core->auth->isSuperAdmin()) { 843 $line .= 844 $this->displayLineActions($id, $module, $actions, false); 845 } 846 847 $line .= 848 '</div>'; 849 850 $line .= 851 '</div>'; 852 853 $count++; 854 855 $res = $current ? $line.$res : $res.$line; 856 } 857 echo 858 $res. 859 '</div>'; 860 861 if(!$count) { 862 echo 863 '<p class="message">'.__('No module matches your search.').'</p>'; 864 } 865 } 647 866 }
Note: See TracChangeset
for help on using the changeset viewer.