View source
<?php
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;
}
}
function export_perm() {
return array(
'export node',
'export bulk nodes',
'export own nodes',
'use PHP to import nodes',
);
}
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;
$access = user_access('export node') || $user->uid && $node->uid == $user->uid && user_access('export own nodes');
$access = $access && (export_is_permitted($node->type) && filter_access($node->format) && node_access('create', $node->type));
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]);
}
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_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) {
$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));
}