You are here

popup_ui.module in Popup 6.x

File

modules/popup_ui/popup_ui.module
View source
<?php

// $Id:

/* ----- Hook implementation ---- */

/**
 * Implementation of hook_enable
 */
function popup_ui_enable() {
  module_load_include('inc', 'popup_ui', 'includes/popup_ui.util');
  _popup_ui_flush_all();
}

/**
 * Implementation of hook_menu
 */
function popup_ui_menu() {
  return array(
    'admin/settings/popup/settings' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'title' => 'Settings',
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -1,
    ),
    'admin/settings/popup/formats' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'description' => 'Manage popup formats available to Views and CCK',
      'file' => 'includes/popup_ui.admin.inc',
      'page arguments' => array(
        'popup_ui_form_formatters',
      ),
      'page callback' => 'drupal_get_form',
      'title' => 'Formats',
      'type' => MENU_LOCAL_TASK,
      'weight' => 1,
    ),
    'admin/settings/popup/formats/delete' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'includes/popup_ui.admin.inc',
      'page callback' => 'popup_ui_delete_format',
      'type' => MENU_CALLBACK,
    ),
    'admin/settings/popup/formats/whipe' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'includes/popup_ui.admin.inc',
      'page callback' => 'popup_ui_whipe_formats',
      'type' => MENU_CALLBACK,
    ),
    'admin/settings/popup/formats/reset' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'includes/popup_ui.admin.inc',
      'page callback' => 'popup_ui_reset',
      'type' => MENU_CALLBACK,
    ),
  );
}

/**
 * Implementation of hook_field_formatter_info
 */
function popup_ui_field_formatter_info() {
  module_load_include('inc', 'popup_ui', 'includes/popup_ui.admin');
  $formatter_info = array();
  $formatters = _popup_ui_formatter_settings();
  foreach ($formatters as $label => $formatter) {
    $formatter_info[str_replace(' ', '_', $label)] = array(
      'label' => $label,
      'field types' => array(
        'nodereference',
      ),
    );
  }
  return $formatter_info;
}

/**
 *  Implementation of hook_features_api
 */
function popup_ui_features_api() {
  return array(
    'popupformat' => array(
      'name' => t('Popup formats'),
      'default_hook' => 'popupformat_defaults',
      'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON,
      'file' => drupal_get_path('module', 'popup_ui') . '/includes/popup_ui.features.inc',
    ),
  );
}

/**
 * Implementation of hook_popup_attributes_alter
 * Hooked to add format attributes
 */
function popup_ui_popup_attributes_alter(&$attributes) {
  if ($attributes['format']) {
    module_load_include('inc', 'popup_ui', 'includes/popup_ui.admin');
    $formats = _popup_ui_formatter_settings();
    if (is_array($formats[$attributes['format']])) {
      $format_attributes = array_filter($formats[$attributes['format']]);
    }
    if ($format_attributes) {
      $attributes = array_merge($format_attributes, array_filter($attributes));
    }
    unset($attributes['format']);
  }
}

/* ---- Themeing hooks ---- */

/**
 * Implementation of hook_theme
 */
function popup_ui_theme() {
  module_load_include('inc', 'popup_ui', 'includes/popup_ui.admin');
  $formatters = _popup_ui_formatter_settings();
  $theme = array();
  foreach ($formatters as $label => $formatter) {
    $theme['popup_ui_formatter_' . str_replace(' ', '_', $label)] = array(
      'function' => 'theme_popup_field',
      'arguments' => array(
        'element' => NULL,
      ),
    );
  }
  $theme['popup_ui_form_formatters'] = array(
    'arguments' => array(
      'form' => array(),
    ),
  );
  $theme['table'] = array(
    'arguments' => array(
      'header' => array(),
      'rows' => array(),
      'attributes' => array(),
      'caption' => NULL,
    ),
    'function' => 'popup_ui_table',
  );
  return $theme;
}

/**
 * Implementation of theme_popup_field
 */
function theme_popup_field($element = NULL) {
  module_load_include('inc', 'popup', 'includes/popup.api');
  module_load_include('inc', 'popup_ui', 'includes/popup_ui.admin');
  $formatters = _popup_ui_formatter_settings();
  module_load_include('inc', 'popup', 'processing');
  $attributes = $formatters[str_replace('_', ' ', $element['#formatter'])];
  if ($element['#item']['nid']) {
    $attributes['node'] = $element['#item']['nid'];
    $popup = _popup_node($attributes);
  }
  return $popup;
}

/**
 * Implementation of theme_table
 * Wraps tables to provide horisontal scrolling if needed
 */
function popup_ui_table($header, $rows, $attributes = array(), $caption = NULL) {
  return '<div class="table-wrapper">' . theme_table($header, $rows, $attributes, $caption) . '</div>';
}

/**
 * Implementation of theme_popup_ui_form_formatters
 * Themes the formats settings form
 */
function theme_popup_ui_form_formatters($form) {
  $rows = array();
  $header = array(
    t('Administrative label'),
    array(
      'data' => '<div>' . t('Display') . '</div>' . t('Origin at'),
      'class' => 'section',
    ),
    t('Expand to'),
    t('Effect'),
    t('Style'),
    t('Opacity'),
    t('Width'),
    array(
      'data' => '<div>' . t('Behavior') . '</div>' . t('Activate'),
      'class' => 'section',
    ),
    t('Close'),
    t('AJAX'),
    array(
      'data' => '<div>' . t('Node') . '</div>' . t('Teaser'),
      'class' => 'section',
    ),
    t('Page'),
    t('Links'),
    t('Panel'),
    array(
      'data' => '<div>' . t('Menu') . '</div>' . t('Inline'),
      'class' => 'section',
    ),
    t('Flat'),
    array(
      'data' => '<div>' . t('Submenus') . '</div>' . t('Origin'),
      'class' => 'section',
    ),
    t('Expand'),
    array(
      'data' => '',
      'class' => 'section',
    ),
  );
  foreach ($form['rows'] as $row_id => $row) {
    if (substr($row_id, 0, 1) != '#') {
      foreach ($row as $field_id => $field) {
        if (substr($field_id, 0, 1) != '#') {
          if ($field_id == 'origin' || $field_id == 'teaser' || $field_id == 'activate' || $field_id == 'inline' || $field_id == 'submenu-origin' || $field_id == 'ops') {
            $table_rows[$row_id]['data'][] = array(
              'data' => drupal_render($form['rows'][$row_id][$field_id]),
              'class' => 'section',
            );
          }
          else {
            $table_rows[$row_id]['data'][] = drupal_render($form['rows'][$row_id][$field_id]);
          }
        }
      }
    }
  }
  $form['table'] = array(
    '#value' => '<div class="form-item"><label>' . t('Popup formats') . ':</label>' . theme('table', $header, $table_rows, array(
      'id' => 'format-table',
      'class' => "popup-settings-table",
    )) . '</div>',
  );
  $output .= drupal_render($form);
  return $output;
}

Functions

Namesort descending Description
popup_ui_enable Implementation of hook_enable
popup_ui_features_api Implementation of hook_features_api
popup_ui_field_formatter_info Implementation of hook_field_formatter_info
popup_ui_menu Implementation of hook_menu
popup_ui_popup_attributes_alter Implementation of hook_popup_attributes_alter Hooked to add format attributes
popup_ui_table Implementation of theme_table Wraps tables to provide horisontal scrolling if needed
popup_ui_theme Implementation of hook_theme
theme_popup_field Implementation of theme_popup_field
theme_popup_ui_form_formatters Implementation of theme_popup_ui_form_formatters Themes the formats settings form