You are here

popup_filter.module in Popup 7

File

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

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

/**
 * Implementation of hook_menu
 */
function popup_filter_menu() {
  $path = drupal_get_path('module', 'popup_filter');
  return array(
    'ajax/popup-filter/getnode' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'popup_filter.admin.inc',
      'file path' => $path . '/includes',
      'page callback' => 'popup_filter_ajax_getnode',
      'page arguments' => array(
        3,
      ),
      'type' => MENU_CALLBACK,
    ),
    'ajax/popup-filter/getdeltas' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'popup_filter.admin.inc',
      'file path' => $path . '/includes',
      'page callback' => 'popup_filter_ajax_getdeltas',
      'type' => MENU_CALLBACK,
    ),
    'ajax/popup-filter/getdisplays' => array(
      'access arguments' => array(
        'administer popup elements',
      ),
      'file' => 'popup_filter.admin.inc',
      'file path' => $path . '/includes',
      'page callback' => 'popup_filter_ajax_getdisplays',
      'type' => MENU_CALLBACK,
    ),
  );
}

/**
 * Implementation of hook_filter_info().
 */
function popup_filter_filter_info() {
  $filters['popup_tags'] = array(
    'title' => t('Popup filter'),
    'description' => t('Replaces [popup filter tags] with popup content. Administrator use only!'),
    'process callback' => 'popup_filter_eval',
    'cache' => FALSE,
  );
  return $filters;
}

/**
 * Implementation of hook_form_alter
 *
 * Hooked to ad popup filter form to the bottom of filtered inputs
 *
 * @param $form
 * @param $form_state
 * @param $form_id
 */
function popup_filter_form_alter(&$form, &$form_state, $form_id) {
  $block_form = in_array($form_id, array(
    'block_add_block_form',
    'block_admin_configure',
  ));
  $node_form = preg_match('/node_form$/', $form_id);
  if (user_access('administer popup elements') && ($block_form || $node_form)) {
    module_load_include('inc', 'popup', 'includes/popup.api');
    module_load_include('inc', 'popup_filter', 'includes/popup_filter.admin');
    $attributes = array(
      'activate' => 'click',
      'class' => 'popup-filter-admin-form',
      'close' => TRUE,
      'effect' => 'slide-down-fade',
      'expand' => 'bottom-left',
      'origin' => 'bottom-right',
      'width' => 650,
    );
    $popup_form = popup_filter_insert_form();
    $popup_form = popup_element(t('Insert popup element'), $popup_form, $attributes);
    if ($block_form) {
      if (isset($form['settings']['body_field'])) {
        $form['settings']['body_field']['#prefix'] = isset($form['settings']['body_field']['#prefix']) ? $form['settings']['body_field']['#prefix'] . $popup_form : $popup_form;
      }
    }
    else {
      if (isset($form['body'])) {
        $form['body']['#prefix'] = isset($form['body']['#prefix']) ? $form['body']['#prefix'] . $popup_form : $popup_form;
      }
    }
  }
}

/* ----- Callbacks ---- */

/**
 *  Popup filter callback
 */
function popup_filter_eval($text) {
  module_load_include('inc', 'popup_filter', 'includes/popup_filter.processing');
  return popup_filter_process_text($text);
}

Functions

Namesort descending Description
popup_filter_eval Popup filter callback
popup_filter_filter_info Implementation of hook_filter_info().
popup_filter_form_alter Implementation of hook_form_alter
popup_filter_menu Implementation of hook_menu