You are here

function om_block_classes_get in OM Tools 6.2

Same name and namespace in other branches
  1. 8.2 tools/block/block.inc \om_block_classes_get()
  2. 7.2 tools/block/block.inc \om_block_classes_get()

default blocks classes

1 call to om_block_classes_get()
om_block_classes in tools/block/block.inc
Block Classes Form

File

tools/block/block.inc, line 60
Block Tools

Code

function om_block_classes_get($block_defaults = array(), $reset = FALSE) {
  $theme_default = variable_get('theme_default', 'garland');

  // boxes table is for custom blocks
  $box_result = db_query("SELECT bid, info FROM {boxes} ORDER BY info ASC");
  $box_classes = array();
  while ($box_record = db_fetch_object($box_result)) {
    $box_classes[$box_record->bid] = om_tools_class_safe($box_record->info);
  }

  // default, module generated blocks
  $block_result = db_query("SELECT module, delta FROM {blocks} WHERE theme = '%s' ORDER BY module, delta ASC", $theme_default);
  $new_blocks = 0;
  $current_blocks = array();
  while ($block_record = db_fetch_object($block_result)) {

    // new blocks
    if (!isset($block_defaults['block_classes___' . $block_record->module . '___' . $block_record->delta]) || $reset == TRUE) {
      $new_blocks++;
      if ($block_record->module == 'block') {
        $classes = 'block-' . $box_classes[$block_record->delta];
      }
      else {
        $classes = 'block-' . $block_record->module . '-' . $block_record->delta;
      }
    }
    else {
      $classes = $block_defaults['block_classes___' . $block_record->module . '___' . $block_record->delta];
    }

    // this will ignore non-existing blocks
    $current_blocks[$block_record->module]['block_classes___' . $block_record->module . '___' . $block_record->delta] = $classes;
  }
  $new_blocks > 1 ? $message = 'There are ' . $new_blocks . ' new blocks, save your settings to add these new blocks.' : ($message = 'There is ' . $new_blocks . ' new block, save your settings to add this new block.');
  if ($new_blocks) {
    drupal_set_message(t($message));
  }
  $current_blocks['block_classes_switch'] = isset($block_defaults['block_classes_switch']) ? $block_defaults['block_classes_switch'] : 0;
  $current_blocks['block_classes_reset'] = isset($block_defaults['block_classes_reset']) ? $block_defaults['block_classes_reset'] : 0;
  ksort($current_blocks);
  return $current_blocks;
}