You are here

function modal_page_page_build in Modal 7

Implements hook_page_build().

File

./modal_page.module, line 24
Main file for the Modal Page.

Code

function modal_page_page_build(&$page) {
  $path_modal_page = drupal_get_path('module', 'modal_page');
  $external_js = variable_get('modal_page_external_js', TRUE);
  if ($external_js) {
    $page['content']['#attached']['js'][] = array(
      'type' => 'external',
      'data' => 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js',
    );
    $page['content']['#attached']['js'][] = array(
      'type' => 'external',
      'data' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',
    );
    $page['content']['#attached']['js'][] = array(
      'type' => 'file',
      'data' => $path_modal_page . '/js/jquery-noconflict.js',
    );
  }
  $page['content']['#attached']['css'][] = array(
    'type' => 'file',
    'data' => $path_modal_page . '/css/modal_page.css',
  );
  $modal_page_settings = variable_get('modal_page_modals');
  if (empty($modal_page_settings)) {
    return FALSE;
  }
  $modals_settings = explode(PHP_EOL, $modal_page_settings);
  foreach ($modals_settings as $modal_settings) {

    // Default values.
    $path = $title = $text = $button = '';
    $modal = explode('|', $modal_settings);
    if (!empty($modal[0])) {
      $path = $modal[0];
    }
    if ($path != '<front>') {
      $path = filter_xss($modal[0]);
      $path = trim($path);
    }
    if (!empty($modal[1])) {
      $title = filter_xss($modal[1]);
      $title = trim($title);
    }

    // Check HTML tags.
    $modal_page_allowed_tags = variable_get('modal_page_allowed_tags');
    if (!empty($modal_page_allowed_tags)) {
      $modal_page_allowed_tags = explode(PHP_EOL, $modal_page_allowed_tags);
      $modal_page_allowed_tags = preg_replace('/\\s/', '', $modal_page_allowed_tags);
    }
    if (!empty($modal[2])) {
      $text = empty($modal_page_allowed_tags) ? filter_xss($modal[2]) : filter_xss($modal[2], $modal_page_allowed_tags);
      $text = trim($text);
    }
    if (!empty($modal[3])) {
      $button = filter_xss($modal[3]);
      $button = trim($button);
    }
    $current_path = drupal_get_path_alias(current_path());
    if (drupal_is_front_page()) {
      $current_path = '<front>';
    }
    if ($path == $current_path) {
      $page['content']['#attached']['js'][] = array(
        'type' => 'file',
        'data' => $path_modal_page . '/js/modal_page.js',
      );
      $modal = theme('modal_page_modal', array(
        'title' => $title,
        'text' => $text,
        'button' => $button,
      ));
      $page['page_top']['slidedown_templates'] = array(
        '#weight' => -1000,
        '#markup' => $modal,
      );
      break;
    }
  }
}