View source
<?php
require_once 'batch/oa_export.batch.export.inc';
require_once 'batch/oa_export.batch.import.inc';
require_once 'entity/oa_export.entity.export.inc';
require_once 'entity/oa_export.entity.import.inc';
require_once 'fields/oa_export.fields.export.inc';
require_once 'fields/oa_export.fields.import.inc';
require_once 'menus/oa_export.menus.export.inc';
require_once 'menus/oa_export.menus.import.inc';
require_once 'module/oa_export.module.export.inc';
require_once 'form/oa_export.form.import.inc';
require_once 'formats/json.inc';
require_once 'formats/oa_export.file.inc';
require_once 'formats/oa_export.formats.inc';
define('OA_EXPORT_DEFAULT_MODULE_PATH', 'sites/all/modules');
define('BLUEPRINT_SPACE', 'field_oa_clone_space');
define('OA_EXPORT_FILES', 'files');
define('OA_EXPORT_DIR', 'oa_export');
define('OA_EXPORT_TEMP_DIR', '_tmp_oa_export');
define('OA_EXPORT_REDIRECT', 'admin/structure/taxonomy/space_type');
define('OA_EXPORT_JSON_FILE', 'entities');
function oa_export_menu() {
return array(
'blueprint/download/%taxonomy_term' => array(
'title' => 'Blueprint Download',
'access callback' => 'user_access',
'access arguments' => array(
'download blueprint',
),
'page callback' => 'oa_export_batch_export',
'page arguments' => array(
2,
),
'type' => MENU_CALLBACK,
),
'blueprint/export/%taxonomy_term' => array(
'title' => 'Blueprint Export',
'description' => 'Exports you blueprint to a module.',
'access callback' => 'user_access',
'access arguments' => array(
'export blueprint',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'oa_export_generate_module_form',
2,
),
'type' => MENU_CALLBACK,
),
'blueprint/import' => array(
'title' => 'Blueprint Import',
'access callback' => 'user_access',
'access arguments' => array(
'import blueprint',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'oa_export_blueprint_import_form',
),
'type' => MENU_LOCAL_ACTION,
),
'oa_export/download' => array(
'title' => 'Blueprint Download',
'access callback' => 'user_access',
'access arguments' => array(
'export blueprint',
),
'page callback' => 'oa_export_batch_file_download_finished_redirect',
),
);
}
function oa_export_permission() {
return array(
'download blueprint' => array(
'title' => t('Blueprint Download'),
'description' => t('This role will be allowed to download blueprints to an archived file.'),
),
'export blueprint' => array(
'title' => t('Blueprint Export'),
'description' => t('This role will be allowed to export a blueprints to a modules.'),
),
'import blueprint' => array(
'title' => t('Blueprint Import'),
'description' => t('This role will be allowed to import blueprints.'),
),
);
}
function oa_export_theme($existing, $type, $theme, $path) {
return array(
'blueprint_download_page' => array(
'render element' => 'content',
'template' => 'blueprint-download-page',
'path' => drupal_get_path('module', 'oa_export') . '/theme',
),
);
}
function oa_export_preprocess_blueprint_download_page(&$variables) {
$variables['download_path'] = $_SESSION['oa_export']['download_path'];
$variables['download_redirect'] = url(OA_EXPORT_REDIRECT);
}
function oa_export_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($_GET['q'] === 'admin/structure/taxonomy/space_type') {
$item = menu_get_item('blueprint/import');
$item['title'] = t('Import Blueprint');
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
function oa_export_preprocess_table(&$vars) {
if ($_GET['q'] == 'admin/structure/taxonomy/space_type') {
$rows =& $vars['rows'];
foreach ($rows as $key => &$row) {
list(, $tid) = explode(':', $key);
$last_key = array_keys($row['data']);
$end = end($last_key);
$row['data'][$end] .= ' ' . l(t('download'), 'blueprint/download/' . $tid);
$row['data'][$end] .= ' ' . l(t('export'), 'blueprint/export/' . $tid);
}
}
}
function oa_export_import_decode_data($path) {
if ($json = file_get_contents($path)) {
return oa_export_json_import($json);
}
else {
drupal_set_message(t('Error getting the contents of %path.', array(
'%path' => $path,
)));
}
}
function oa_export_get_comments($nid) {
if (module_exists('comment')) {
$comments = db_select('comment', 'c')
->fields('c', array(
'cid',
'nid',
))
->condition('nid', $nid, '=')
->execute()
->fetchAllKeyed();
return array_keys($comments);
}
else {
return array();
}
}
function oa_export_file($file) {
$file_source = drupal_realpath($file->uri);
if (!file_exists($_SESSION['oa_export']['files_directory'] . '/' . $file->filename)) {
if (oa_export_validate_directory()) {
$new_file = file_unmanaged_copy($file_source, $_SESSION['oa_export']['files_directory']);
if (!$new_file) {
}
}
}
}
function oa_export_validate_directory() {
if (file_exists($_SESSION['oa_export']['files_directory'])) {
return TRUE;
}
else {
return FALSE;
}
}
function oa_export_file_full_path($path, $filename) {
if (substr($path, -1) != DIRECTORY_SEPARATOR) {
$path .= DIRECTORY_SEPARATOR;
}
return $path . $filename;
}
function oa_export_remove_missing_entity($entity, $entity_type, $field_name, &$results) {
list($entity_id) = entity_extract_ids($entity_type, $entity);
$field_info = field_info_field($field_name);
if (isset($results['export'][$entity_type . ':' . $entity_id])) {
$results['export'][$entity_type . ':' . $entity_id]->{$field_name} = array();
$results['messages'][] = t("The <strong>!type</strong>, for field <strong>!field</strong> could not be found. The '!type' entity (!entity_id) titled <strong>'!label'</strong> was exported without it.", array(
'!type' => $field_info['type'],
'!field' => $field_name,
'!entity_id' => $entity_id,
'!type' => $entity_type,
'!label' => entity_label($entity_type, $entity),
));
}
$entity->{$field_name} = array();
}
function oa_export_oa_import_remove_entity_alter($entities) {
foreach ($entities as $key => $entity) {
list($type, $id) = explode(':', $key);
if ($type == 'taxonomy_term') {
}
}
}
function oa_export_cleanup($directory = NULL, $goto = NULL) {
unset($_SESSION['oa_export']);
if (isset($directory)) {
oa_export_remove_directory($directory);
}
if (isset($goto)) {
drupal_goto($goto);
}
}
function oa_export_verify_blueprint($blueprint) {
$wrapper = entity_metadata_wrapper('taxonomy_term', $blueprint);
$export_enabled = $wrapper->field_oa_clone_enabled
->value();
if (!$export_enabled) {
drupal_set_message(t('Can only export terms that clone a specific space.'), 'error');
oa_export_cleanup(NULL, OA_EXPORT_REDIRECT);
}
}
function _oa_export_remove_recursion($o) {
static $replace;
if (!isset($replace)) {
$replace = create_function('$m', '$r="\\x00{$m[1]}ecursion_oa";return \'s:\'.strlen($r.$m[2]).\':"\'.$r.$m[2].\'";\';');
}
if (is_array($o) || is_object($o)) {
$re = '#(r|R):([0-9]+);#';
$serialize = serialize($o);
if (preg_match($re, $serialize)) {
$last = $pos = 0;
while (false !== ($pos = strpos($serialize, 's:', $pos))) {
$chunk = substr($serialize, $last, $pos - $last);
if (preg_match($re, $chunk)) {
$length = strlen($chunk);
$chunk = preg_replace_callback($re, $replace, $chunk);
$serialize = substr($serialize, 0, $last) . $chunk . substr($serialize, $last + ($pos - $last));
$pos += strlen($chunk) - $length;
}
$pos += 2;
$last = strpos($serialize, ':', $pos);
$length = substr($serialize, $pos, $last - $pos);
$last += 4 + $length;
$pos = $last;
}
$serialize = substr($serialize, 0, $last) . preg_replace_callback($re, $replace, substr($serialize, $last));
$o = unserialize($serialize);
}
}
return $o;
}