You are here

export.module in Node export 6

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

File

export.module
View source
<?php

// $Name$

/**
 * Implementation of hook_help().
 */
function export_help($path, $arg) {
  switch ($path) {
    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',
    'import nodes',
  );
}

/**
 * Implementation of hook_menu().
 */
function export_menu() {
  $items['admin/settings/export'] = array(
    'access arguments' => array(
      'administer site configuration',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'export_settings',
    ),
    'title' => t('Export module'),
    'file' => 'export.pages.inc',
    'description' => t('Allows users to export (copy then edit) an existing node.'),
  );
  $items['node/%node/export'] = array(
    'access callback' => 'export_access',
    'access arguments' => array(
      1,
    ),
    'page callback' => 'export_node_export',
    'page arguments' => array(
      1,
    ),
    'title' => t('Export'),
    'weight' => 5,
    'file' => 'export.pages.inc',
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/content/import'] = array(
    'access arguments' => array(
      'import nodes',
    ),
    'page callback' => 'export_node_import',
    'title' => t('Import'),
    'file' => 'export.pages.inc',
    'type' => MENU_NORMAL_ITEM,
    'description' => t('Allows users to import a node from another site.'),
  );
  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');

  // Make sure the user can view the original node content.
  $access = $access && node_access('view', $node);

  // 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.
  drupal_alter("export_access", $access, $node);
  return $access;
}
function export_is_permitted($type) {
  $omitted = variable_get('export_omitted', array());
  return empty($omitted[$type]);
}

/**
 * Implementation of hook_mode_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_views_api.
 */
function export_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'export') . '/views',
  );
}

/**
 * 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) {
  module_load_include('inc', 'export', 'export.pages');
  $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_mode_type().
export_perm Implementation of hook_perm().
export_views_api Implementation of hook_views_api.