You are here

function sheetnode_ethercalc_sheetnode_plugins in Sheetnode 6

Same name and namespace in other branches
  1. 7.2 modules/sheetnode_ethercalc/sheetnode_ethercalc.module \sheetnode_ethercalc_sheetnode_plugins()
  2. 7 modules/sheetnode_ethercalc/sheetnode_ethercalc.module \sheetnode_ethercalc_sheetnode_plugins()

Implementation of hook_sheetnode_plugins().

File

modules/sheetnode_ethercalc/sheetnode_ethercalc.module, line 9

Code

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);
    }
    foreach (array(
      'socket.io/socket.io.js#',
      'zappa/zappa.js#',
      'static/md5.js#',
      'player/broadcast.js#',
      'player/main.js#',
    ) as $js) {

      // http://www.zites.net/en/load-external-javascript-files-drupal-6
      $external_js = $ethercalc_path . '/' . $js;
      drupal_add_js('document.write(unescape("%3Cscript src=\'' . $external_js . '\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline');
    }
  }
}