[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/ -> blocks.php (source)

   1  <?php
   2  
   3      // Allows the admin to configure blocks (hide/show, uninstall and configure)
   4  
   5      require_once('../config.php');
   6      require_once($CFG->libdir.'/adminlib.php');
   7      require_once($CFG->libdir.'/tablelib.php');
   8  
   9      admin_externalpage_setup('manageblocks');
  10  
  11      $confirm  = optional_param('confirm', 0, PARAM_BOOL);
  12      $hide     = optional_param('hide', 0, PARAM_INT);
  13      $show     = optional_param('show', 0, PARAM_INT);
  14      $unprotect = optional_param('unprotect', 0, PARAM_INT);
  15      $protect = optional_param('protect', 0, PARAM_INT);
  16  
  17  /// Print headings
  18  
  19      $strmanageblocks = get_string('manageblocks');
  20      $struninstall = get_string('uninstallplugin', 'core_admin');
  21      $strversion = get_string('version');
  22      $strhide = get_string('hide');
  23      $strshow = get_string('show');
  24      $strsettings = get_string('settings');
  25      $strcourses = get_string('blockinstances', 'admin');
  26      $strname = get_string('name');
  27      $strshowblockcourse = get_string('showblockcourse');
  28      $strprotecthdr = get_string('blockprotect', 'admin'). $OUTPUT->help_icon('blockprotect','admin');
  29      $strprotect = get_string('blockprotect', 'admin');
  30      $strunprotect = get_string('blockunprotect', 'admin');
  31  
  32  /// If data submitted, then process and store.
  33  
  34      if (!empty($hide) && confirm_sesskey()) {
  35          if (!$block = $DB->get_record('block', array('id'=>$hide))) {
  36              print_error('blockdoesnotexist', 'error');
  37          }
  38          $DB->set_field('block', 'visible', '0', array('id'=>$block->id));      // Hide block
  39          core_plugin_manager::reset_caches();
  40          admin_get_root(true, false);  // settings not required - only pages
  41      }
  42  
  43      if (!empty($show) && confirm_sesskey() ) {
  44          if (!$block = $DB->get_record('block', array('id'=>$show))) {
  45              print_error('blockdoesnotexist', 'error');
  46          }
  47          $DB->set_field('block', 'visible', '1', array('id'=>$block->id));      // Show block
  48          core_plugin_manager::reset_caches();
  49          admin_get_root(true, false);  // settings not required - only pages
  50      }
  51  
  52      if (!isset($CFG->undeletableblocktypes) || (!is_array($CFG->undeletableblocktypes) && !is_string($CFG->undeletableblocktypes))) {
  53          $undeletableblocktypes = array('navigation', 'settings');
  54      } else if (is_string($CFG->undeletableblocktypes)) {
  55          $undeletableblocktypes = explode(',', $CFG->undeletableblocktypes);
  56      } else {
  57          $undeletableblocktypes = $CFG->undeletableblocktypes;
  58      }
  59  
  60      if (!empty($protect) && confirm_sesskey()) {
  61          if (!$block = $DB->get_record('block', array('id'=>$protect))) {
  62              print_error('blockdoesnotexist', 'error');
  63          }
  64          if (!in_array($block->name, $undeletableblocktypes)) {
  65              $undeletableblocktypes[] = $block->name;
  66              set_config('undeletableblocktypes', implode(',', $undeletableblocktypes));
  67          }
  68          admin_get_root(true, false);  // settings not required - only pages
  69      }
  70  
  71      if (!empty($unprotect) && confirm_sesskey()) {
  72          if (!$block = $DB->get_record('block', array('id'=>$unprotect))) {
  73              print_error('blockdoesnotexist', 'error');
  74          }
  75          if (in_array($block->name, $undeletableblocktypes)) {
  76              $undeletableblocktypes = array_diff($undeletableblocktypes, array($block->name));
  77              set_config('undeletableblocktypes', implode(',', $undeletableblocktypes));
  78          }
  79          admin_get_root(true, false);  // settings not required - only pages
  80      }
  81  
  82      echo $OUTPUT->header();
  83      echo $OUTPUT->heading($strmanageblocks);
  84  
  85  /// Main display starts here
  86  
  87  /// Get and sort the existing blocks
  88  
  89      if (!$blocks = $DB->get_records('block', array(), 'name ASC')) {
  90          print_error('noblocks', 'error');  // Should never happen
  91      }
  92  
  93      $incompatible = array();
  94  
  95  /// Print the table of all blocks
  96  
  97      $table = new flexible_table('admin-blocks-compatible');
  98  
  99      $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'undeletable', 'settings', 'uninstall'));
 100      $table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strprotecthdr, $strsettings, $struninstall));
 101      $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
 102      $table->set_attribute('class', 'admintable blockstable generaltable');
 103      $table->set_attribute('id', 'compatibleblockstable');
 104      $table->setup();
 105      $tablerows = array();
 106  
 107      // Sort blocks using current locale.
 108      $blocknames = array();
 109      foreach ($blocks as $blockid=>$block) {
 110          $blockname = $block->name;
 111          if (file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) {
 112              $blocknames[$blockid] = get_string('pluginname', 'block_'.$blockname);
 113          } else {
 114              $blocknames[$blockid] = $blockname;
 115          }
 116      }
 117      core_collator::asort($blocknames);
 118  
 119      foreach ($blocknames as $blockid=>$strblockname) {
 120          $block = $blocks[$blockid];
 121          $blockname = $block->name;
 122          $dbversion = get_config('block_'.$block->name, 'version');
 123  
 124          if (!file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) {
 125              $blockobject  = false;
 126              $strblockname = '<span class="notifyproblem">'.$strblockname.' ('.get_string('missingfromdisk').')</span>';
 127              $plugin = new stdClass();
 128              $plugin->version = $dbversion;
 129  
 130          } else {
 131              $plugin = new stdClass();
 132              $plugin->version = '???';
 133              if (file_exists("$CFG->dirroot/blocks/$blockname/version.php")) {
 134                  include("$CFG->dirroot/blocks/$blockname/version.php");
 135              }
 136  
 137              if (!$blockobject  = block_instance($block->name)) {
 138                  $incompatible[] = $block;
 139                  continue;
 140              }
 141          }
 142  
 143          if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('block_'.$blockname, 'manage')) {
 144              $uninstall = html_writer::link($uninstallurl, $struninstall);
 145          } else {
 146              $uninstall = '';
 147          }
 148  
 149          $settings = ''; // By default, no configuration
 150          if ($blockobject and $blockobject->has_config()) {
 151              $blocksettings = admin_get_root()->locate('blocksetting' . $block->name);
 152  
 153              if ($blocksettings instanceof admin_externalpage) {
 154                  $settings = '<a href="' . $blocksettings->url .  '">' . get_string('settings') . '</a>';
 155              } else if ($blocksettings instanceof admin_settingpage) {
 156                  $settings = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=blocksetting'.$block->name.'">'.$strsettings.'</a>';
 157              } else if (!file_exists($CFG->dirroot.'/blocks/'.$block->name.'/settings.php')) {
 158                  // If the block's settings node was not found, we check that the block really provides the settings.php file.
 159                  // Note that blocks can inject their settings to other nodes in the admin tree without using the default locations.
 160                  // This can be done by assigning null to $setting in settings.php and it is a valid case.
 161                  debugging('Warning: block_'.$block->name.' returns true in has_config() but does not provide a settings.php file',
 162                      DEBUG_DEVELOPER);
 163              }
 164          }
 165  
 166          // MDL-11167, blocks can be placed on mymoodle, or the blogs page
 167          // and it should not show up on course search page
 168  
 169          $totalcount = $DB->count_records('block_instances', array('blockname'=>$blockname));
 170          $count = $DB->count_records('block_instances', array('blockname'=>$blockname, 'pagetypepattern'=>'course-view-*'));
 171  
 172          if ($count>0) {
 173              $blocklist = "<a href=\"{$CFG->wwwroot}/course/search.php?blocklist=$blockid&amp;sesskey=".sesskey()."\" ";
 174              $blocklist .= "title=\"$strshowblockcourse\" >$totalcount</a>";
 175          }
 176          else {
 177              $blocklist = "$totalcount";
 178          }
 179          $class = ''; // Nothing fancy, by default
 180  
 181          if (!$blockobject) {
 182              // ignore
 183              $visible = '';
 184          } else if ($blocks[$blockid]->visible) {
 185              $visible = '<a href="blocks.php?hide='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strhide.'">'.
 186                         '<img src="'.$OUTPUT->pix_url('t/hide') . '" class="iconsmall" alt="'.$strhide.'" /></a>';
 187          } else {
 188              $visible = '<a href="blocks.php?show='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strshow.'">'.
 189                         '<img src="'.$OUTPUT->pix_url('t/show') . '" class="iconsmall" alt="'.$strshow.'" /></a>';
 190              $class = 'dimmed_text';
 191          }
 192  
 193          if ($dbversion == $plugin->version) {
 194              $version = $dbversion;
 195          } else {
 196              $version = "$dbversion ($plugin->version)";
 197          }
 198  
 199          if (!$blockobject) {
 200              // ignore
 201              $undeletable = '';
 202          } else if (in_array($blockname, $undeletableblocktypes)) {
 203              $undeletable = '<a href="blocks.php?unprotect='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strunprotect.'">'.
 204                         '<img src="'.$OUTPUT->pix_url('t/unlock') . '" class="iconsmall" alt="'.$strunprotect.'" /></a>';
 205          } else {
 206              $undeletable = '<a href="blocks.php?protect='.$blockid.'&amp;sesskey='.sesskey().'" title="'.$strprotect.'">'.
 207                         '<img src="'.$OUTPUT->pix_url('t/lock') . '" class="iconsmall" alt="'.$strprotect.'" /></a>';
 208          }
 209  
 210          $row = array(
 211              $strblockname,
 212              $blocklist,
 213              $version,
 214              $visible,
 215              $undeletable,
 216              $settings,
 217              $uninstall,
 218          );
 219          $table->add_data($row, $class);
 220      }
 221  
 222      $table->print_html();
 223  
 224      if (!empty($incompatible)) {
 225          echo $OUTPUT->heading(get_string('incompatibleblocks', 'blockstable', 'admin'));
 226  
 227          $table = new flexible_table('admin-blocks-incompatible');
 228  
 229          $table->define_columns(array('block', 'uninstall'));
 230          $table->define_headers(array($strname, $struninstall));
 231          $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
 232  
 233          $table->set_attribute('class', 'incompatibleblockstable generaltable');
 234  
 235          $table->setup();
 236  
 237          foreach ($incompatible as $block) {
 238              if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('block_'.$block->name, 'manage')) {
 239                  $uninstall = html_writer::link($uninstallurl, $struninstall);
 240              } else {
 241                  $uninstall = '';
 242              }
 243              $table->add_data(array(
 244                  $block->name,
 245                  $uninstall,
 246              ));
 247          }
 248          $table->print_html();
 249      }
 250  
 251      echo $OUTPUT->footer();
 252  
 253  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1