You are here

tinybox.module in TinyBox (Simple Splash) 7

Same filename and directory in other branches
  1. 6 tinybox.module
  2. 7.2 tinybox.module

File

tinybox.module
View source
<?php

/**
 * Implements hook_help().
 */
function tinybox_help($path, $arg) {
  switch ($path) {
    case 'admin/help#tinybox':
      $output = t('<p>TinyBox is a lightweight and standalone modal window script. New update to the TinyBox modal box script brings a ton of new features and still clocks in under 5KB. The script now supports iframes and images natively. You can POST with Ajax. Clicking ESC will close the window. Callback functions can be passed for load and close events. You can set CSS IDs to override the default styling. CSS position can be toggled between fixed and absolute. The mask opacity can be sent. You have full control over window location. And of course there is now a close button out of the box you can toggle.</p>');
      return $output;
  }
}

/**
 * Implements hook_perm().
 */
function tinybox_permission() {
  return array(
    'administer tinybox' => array(
      'title' => t('Administer TinyBox'),
      'description' => t('Perform maintenance tasks for TinyBox'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function tinybox_menu() {
  $items = array();
  $items['admin/config/content/tinybox'] = array(
    'title' => 'Tinybox settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'tinybox_settings',
    ),
    'access arguments' => array(
      'administer tinybox',
    ),
    'file' => 'tinybox.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_init().
 */
function tinybox_init() {
  global $uid;

  // Necessary to check if we're on the frontpage
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

  //Tinybox for Splash Screen
  $tinybox_splash_source_value = variable_get('tinybox_splash_source_value', '');
  $tinybox_width = variable_get('tinybox_width', 0);
  $tinybox_height = variable_get('tinybox_height', 0);
  $tinybox_autohide = variable_get('tinybox_autohide', 0);
  $tinybox_css = variable_get('tinybox_css', '');
  $tinybox_css = $tinybox_css == '' ? drupal_get_path('module', 'tinybox') : $tinybox_css;
  if ($tinybox_splash_source_value && drupal_is_front_page()) {
    if (module_exists('overlay') && path_is_admin($_GET['q'])) {

      //Known bug: does not work if F5 pressed!
      return;
    }
    drupal_add_js('sites/all/libraries/tinybox/tinybox.js', 'file');
    drupal_add_css($tinybox_css . '/tinybox.css');
    $tinybox_splash_source_type = variable_get('tinybox_splash_source_type', 'nid');
    $tinybox_splash_delay = variable_get('tinybox_splash_delay', 0);
    if ($tinybox_splash_delay) {
      if (!isset($_SESSION['tinybox_session_time'])) {
        $_SESSION['tinybox_session_time'] = time();
      }
      if (time() - $_SESSION['tinybox_session_time'] <= $tinybox_splash_delay) {
        return;
      }
      else {
        $_SESSION['tinybox_session_time'] = time();
      }
    }
    if ($tinybox_splash_source_type == 'nid') {
      $node = node_load($tinybox_splash_source_value);
      $tinybox_content = $node->body['und']['0']['value'];
    }
    if ($tinybox_splash_source_type == 'content_type') {
      $sql = "SELECT nid FROM {node} n WHERE n.type = :type AND n.status=1 ORDER BY n.created DESC LIMIT 1";
      $result = db_query($sql, array(
        ':type' => $tinybox_splash_source_value,
      ));
      $record = $result
        ->fetchObject();
      $node = node_load($record->nid);
      $tinybox_content = $node->body['und']['0']['value'];
    }
    if ($tinybox_splash_source_type == 'views') {
      if (module_exists('views')) {
        $view = views_get_view($tinybox_splash_source_value);
        if ($view) {
          $view
            ->execute();
          $tinybox_content = $view
            ->render();
        }
        else {
          $tinybox_content = 'Views not found: ' . $tinybox_splash_source_value;
        }
      }
      else {
        $tinybox_content = t('Require Views module.');
      }
    }
    $tinybox_content = str_replace(chr(13), '', $tinybox_content);
    $tinybox_content = str_replace(chr(10), '', $tinybox_content);
    $overlay_check = '';
    if (module_exists('overlay') && $uid == 1) {
      $overlay_check = 'if (Drupal.overlay.isOpen) { return; }';
    }
    drupal_add_js('
      window.onload = function() {
        ' . $overlay_check . '
        TINY.box.show({
          html: \'' . $tinybox_content . '\',
          boxid:\'tbox\',width:' . $tinybox_width . ',height:' . $tinybox_height . ',fixed:false,
          maskid:\'blackmask\',maskopacity:40,
          autohide:' . $tinybox_autohide . ',
          closejs:function(){closeJS()}
        });
        document.getElementsByClassName(\'tmask\')[0].onclick=null;
      }
    ', 'inline');
  }
}

// boxid:\'tbox\',width:750,height:450,fixed:false,maskid:\'bluemask\',maskopacity:40,

Functions

Namesort descending Description
tinybox_help Implements hook_help().
tinybox_init Implements hook_init().
tinybox_menu Implements hook_menu().
tinybox_permission Implements hook_perm().