You are here

function popup_block_preprocess_block in Popup 7

Same name and namespace in other branches
  1. 8 modules/popup_block/popup_block.module \popup_block_preprocess_block()
  2. 7.x modules/popup_block/popup_block.module \popup_block_preprocess_block()
  3. 6.x modules/popup_block/popup_block.module \popup_block_preprocess_block()

File

modules/popup_block/popup_block.module, line 109

Code

function popup_block_preprocess_block(&$variables) {
  module_load_include('inc', 'popup', 'includes/popup.api');
  $settings = _popup_block_settings();
  $block =& $variables['block'];
  $block_settings = isset($settings[$block->module . ':' . $block->delta]) ? $settings[$block->module . ':' . $block->delta] : FALSE;
  $title_length = isset($block_settings['title-length']) ? $block_settings['title-length'] : 10;
  if ($block_settings && $block_settings['active']) {
    $body = $variables['content'];
    $title_candidates = array_filter(array(
      $variables['elements']['#block']->subject,
      substr(strip_tags($body), 0, $title_length) . '...',
      isset($variables['elements'][1]['title']) ? $variables['elements'][1]['title'] : 0,
    ));
    $title = array_shift($title_candidates);
    $attributes = array(
      'block' => TRUE,
      'delta' => $block->delta,
      'format' => $block_settings['format'],
      'module' => $block->module,
      'title' => $title,
      'title-length' => $title_length,
    );

    // Integration with block_titlelink module
    if (!empty($variables['block']->title_link)) {
      $attributes['path'] = $variables['block']->title_link;
      $variables['block']->subject = strip_tags($block->subject);
    }
    drupal_alter('popup_attributes', $attributes);
    $attributes['altered'] = TRUE;
    $variables['content'] = popup_element($attributes['title'], $body, $attributes);
    $variables['block']->subject = '';
  }
}