You are here

export.module in Node export 5.2

Same filename and directory in other branches
  1. 5 export.module
  2. 6 export.module

File

export.module
View source
<?php

/**
 * Implementation of hook_help().
 */
function export_help($section) {
  switch ($section) {
    case 'admin/help#export':
      $output = '<p>' . t('The export module allows users to export an existing node and then import it into another Drupal installation.') . '</p>';
      $output .= '<p>' . t('Users with the "export node" permission can utilize this functionality. A new tab will appear on node pages with the word "Export".') . '</p>';
      return $output;
  }
}

/**
* Implementation of hook_perm().
*/
function export_perm() {
  return array(
    'export node',
    'export bulk nodes',
    'export own nodes',
    'use PHP to import nodes',
  );
}

/**
 * Implementation of hook_menu().
 */
function export_menu($may_cache) {
  include_once drupal_get_path('module', 'export') . "/export.pages.inc";
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/export',
      'title' => t('Export module'),
      'description' => t('Allows users to export (copy then edit) an existing node.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'export_settings',
      'access' => user_access('administer site configuration'),
    );
  }
  else {
    $items[] = array(
      'path' => 'admin/content/import',
      'title' => t('Import Node'),
      'description' => t('Allows users to import a node from another site.'),
      'callback' => 'export_node_import',
      'access' => user_access('use PHP to import nodes'),
    );
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      if ($node->nid) {
        $items[] = array(
          'path' => 'node/' . $node->nid . '/export',
          'title' => t('Export'),
          'callback' => 'export_node_export',
          'callback arguments' => array(
            $node,
          ),
          'access' => export_access($node),
          'type' => MENU_LOCAL_TASK,
          'weight' => 5,
        );
      }
    }
  }
  return $items;
}
function export_access($node) {
  global $user;

  // Check basic permissions first.
  $access = user_access('export node') || $user->uid && $node->uid == $user->uid && user_access('export own nodes');

  // Check additional conditions
  $access = $access && (export_is_permitted($node->type) && filter_access($node->format) && node_access('create', $node->type));

  // Let other modules alter this - for exmple to only allow some users
  // to export specific nodes or types.
  foreach (module_implements('export_access_alter') as $module) {
    $function = $module . '_export_access_alter';
    $function($access, $node);
  }
  return $access;
}
function export_is_permitted($type) {
  $omitted = variable_get('export_omitted', array());
  return empty($omitted[$type]);
}

/**
 * Implementation of hook_node_type().
 */
function export_node_type($op, $type_obj) {
  switch ($op) {
    case 'delete':
      variable_del('export_reset_' . $type_obj->type);
      break;
    case 'update':
      if (!empty($type_obj->old_type) && $type_obj->old_type != $type_obj->type) {
        if (variable_get('export_reset_' . $type_obj->old_type, FALSE)) {
          variable_del('export_reset_' . $type_obj->old_type);
          variable_set('export_reset_' . $type_obj->type, TRUE);
        }
      }
      break;
  }
}

/**
 * Implementation of hook_node_operations.
 */
function export_node_operations() {
  $operations = array();
  if (user_access('export bulk nodes')) {
    $operations = array(
      'export' => array(
        'label' => t('Export nodes'),
        'callback' => 'export_node_bulk',
      ),
    );
  }
  return $operations;
}

/**
 * Callback for 'export' node operation.
 */
function export_node_bulk($nodes) {
  $node_codes = array();
  foreach ($nodes as $nid) {
    $node_codes[] = export_node_export(node_load($nid), TRUE, 1);
  }
  $node_code = "array(\n  " . implode(",\n  ", $node_codes) . ",\n)";
  drupal_set_message(drupal_get_form('export_form', $node_code));
}

Functions

Namesort descending Description
export_access
export_help Implementation of hook_help().
export_is_permitted
export_menu Implementation of hook_menu().
export_node_bulk Callback for 'export' node operation.
export_node_operations Implementation of hook_node_operations.
export_node_type Implementation of hook_node_type().
export_perm Implementation of hook_perm().