You are here

sheetnode_ethercalc.module in Sheetnode 7.2

Module file for the sheetnode_ethercalc module.

This extends sheetnodes to allow syncronising with Ethercalc.

File

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

/**
 * @file
 * Module file for the sheetnode_ethercalc module.
 *
 * This extends sheetnodes to allow syncronising with Ethercalc.
 */
define('SHEETNODE_ETHERCALC_EDIT_ONLY', 1);
define('SHEETNODE_ETHERCALC_EDIT_FIDDLE', 2);

/**
 * Implements hook_sheetnode_plugins().
 */
function sheetnode_ethercalc_sheetnode_plugins($value, $save_element, $context) {

  // Only turn on Ethercalc if we're editing the node.
  if (!empty($save_element) || variable_get('sheetnode_ethercalc_mode', SHEETNODE_ETHERCALC_EDIT_ONLY) == SHEETNODE_ETHERCALC_EDIT_FIDDLE && variable_get('sheetnode_view_mode', SHEETNODE_VIEW_FIDDLE) == SHEETNODE_VIEW_FIDDLE) {
    $ethercalc_host = variable_get('sheetnode_ethercalc_host', '');
    $ethercalc_port = variable_get('sheetnode_ethercalc_port', '8000');
    $ethercalc_path = $GLOBALS['base_url'];
    $ethercalc_path = preg_replace('/(:\\/\\/[^\\/]+).*/', '$1', $ethercalc_path, 1);
    if ($ethercalc_port) {
      $ethercalc_path = preg_replace('/(?:\\:\\d+)?$/', ':' . $ethercalc_port, $ethercalc_path, 1);
    }
    if ($ethercalc_host) {
      $ethercalc_path = preg_replace('/^([^:]*)/', $ethercalc_host, $ethercalc_path, 1);
    }
    drupal_add_js($ethercalc_path . '/socket.io/socket.io.js#', array(
      'weight' => 10,
    ));
    drupal_add_js($ethercalc_path . '/zappa/zappa.js#', array(
      'weight' => 10,
    ));
    drupal_add_js($ethercalc_path . '/static/md5.js#', array(
      'weight' => 10,
    ));
    drupal_add_js($ethercalc_path . '/player/broadcast.js#', array(
      'weight' => 10,
    ));
    drupal_add_js($ethercalc_path . '/player/main.js#', array(
      'weight' => 10,
    ));
  }
}

/**
 * Implements hook_menu().
 */
function sheetnode_ethercalc_menu() {
  $items = array();
  $items['admin/config/content/sheetnode/ethercalc'] = array(
    'title' => 'EtherCalc',
    'access arguments' => array(
      'administer site configuration',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_sheetnode_ethercalc_settings',
    ),
    'description' => 'Administer settings for Sheetnode EtherCalc.',
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Form function for admin/settings/sheetnode/ethercalc.
 */
function _sheetnode_ethercalc_settings($form, &$form_state) {
  $form['sheetnode_ethercalc_host'] = array(
    '#type' => 'textfield',
    '#title' => t('EtherCalc host'),
    '#description' => t('Enter the domain name of the EtherCalc server. Leave blank to use same domain as your Drupal installation.'),
    '#default_value' => variable_get('sheetnode_ethercalc_host', ''),
  );
  $form['sheetnode_ethercalc_port'] = array(
    '#type' => 'textfield',
    '#title' => t('EtherCalc port'),
    '#description' => t('Enter the port of the EtherCalc server.'),
    '#default_value' => variable_get('sheetnode_ethercalc_port', '8000'),
  );
  $form['sheetnode_ethercalc_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Activate EtherCalc on'),
    '#options' => array(
      SHEETNODE_ETHERCALC_EDIT_ONLY => t('Edit mode only'),
      SHEETNODE_ETHERCALC_EDIT_FIDDLE => t('Edit and fiddle modes'),
    ),
    '#default_value' => variable_get('sheetnode_ethercalc_mode', SHEETNODE_ETHERCALC_EDIT_ONLY),
  );
  return system_settings_form($form);
}

Functions

Namesort descending Description
sheetnode_ethercalc_menu Implements hook_menu().
sheetnode_ethercalc_sheetnode_plugins Implements hook_sheetnode_plugins().
_sheetnode_ethercalc_settings Form function for admin/settings/sheetnode/ethercalc.

Constants

Namesort descending Description
SHEETNODE_ETHERCALC_EDIT_FIDDLE
SHEETNODE_ETHERCALC_EDIT_ONLY @file Module file for the sheetnode_ethercalc module.