View source
<?php
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;
}
}
function export_perm() {
return array(
'export node',
'export bulk nodes',
'export own nodes',
'import nodes',
);
}
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;
$access = user_access('export node') || $user->uid && $node->uid == $user->uid && user_access('export own nodes');
$access = $access && node_access('view', $node);
$access = $access && (export_is_permitted($node->type) && filter_access($node->format) && node_access('create', $node->type));
drupal_alter("export_access", $access, $node);
return $access;
}
function export_is_permitted($type) {
$omitted = variable_get('export_omitted', array());
return empty($omitted[$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;
}
}
function export_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'export') . '/views',
);
}
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;
}
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));
}