View source
<?php
function backup_migrate_get_filters($op = NULL) {
static $filters = NULL;
if ($filters === NULL) {
$filters = array();
$definitions = module_invoke_all('backup_migrate_filters');
foreach ($definitions as $definition) {
if (!empty($definition['file'])) {
require_once './' . $definition['file'];
}
$filters[] = new $definition['class']();
}
}
$sort = array();
foreach ($filters as $filter) {
$sort[] = $filter
->weight($op);
}
array_multisort($sort, SORT_ASC, SORT_NUMERIC, $filters);
return $filters;
}
function backup_migrate_backup_migrate_filters() {
return array(
'backup_restore' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.backup_restore.inc',
'class' => 'backup_migrate_filter_backup_restore',
),
'compression' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.compression.inc',
'class' => 'backup_migrate_filter_compression',
),
'encryption' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.encryption.inc',
'class' => 'backup_migrate_filter_encryption',
),
'statusnotify' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.statusnotify.inc',
'class' => 'backup_migrate_filter_statusnotify',
),
'utils' => array(
'file' => drupal_get_path('module', 'backup_migrate') . '/includes/filters.utils.inc',
'class' => 'backup_migrate_filter_utils',
),
);
}
function backup_migrate_filters_invoke_all() {
$args = func_get_args();
$op = array_shift($args);
$out = array();
$filters = backup_migrate_get_filters($op);
foreach ($filters as $filter) {
if (method_exists($filter, $op)) {
switch (count($args)) {
case 1:
$ret = $filter
->{$op}($args[0]);
break;
case 2:
$ret = $filter
->{$op}($args[0], $args[1]);
break;
default:
$ret = call_user_func_array(array(
$filter,
$op,
), $args);
}
$out = array_merge_recursive($out, (array) $ret);
}
}
return $out;
}
function backup_migrate_filters_backup($file, &$settings) {
$filters = backup_migrate_get_filters('backup');
foreach ($filters as $filter) {
if ($file) {
$file = $filter
->backup($file, $settings);
}
}
return $file;
}
function backup_migrate_filters_restore($file, &$settings) {
$filters = backup_migrate_get_filters('restore');
foreach ($filters as $filter) {
if ($file) {
$file = $filter
->restore($file, $settings);
}
}
return $file;
}
function backup_migrate_filters_settings_form($settings, $op) {
$out = backup_migrate_filters_invoke_all($op . '_settings_form', $settings);
$out = backup_migrate_filters_settings_form_set_parents($out);
return $out;
}
function backup_migrate_filters_settings_form_set_parents($form) {
foreach (element_children($form) as $key) {
if (!isset($form[$key]['#parents'])) {
$form[$key]['#parents'] = array(
'filters',
$key,
);
$form[$key] = backup_migrate_filters_settings_form_set_parents($form[$key]);
}
}
return $form;
}
function backup_migrate_filters_settings_form_validate($op, $form, &$form_state) {
backup_migrate_filters_invoke_all($op . '_settings_form_validate', $form, $form_state);
}
function backup_migrate_filters_settings_form_submit($op, $form, &$form_state) {
backup_migrate_filters_invoke_all($op . '_settings_form_submit', $form, $form_state);
}
function backup_migrate_filters_settings_default($op) {
return backup_migrate_filters_invoke_all($op . '_settings_default');
}
function backup_migrate_filters_file_types() {
return backup_migrate_filters_invoke_all('file_types');
}
class backup_migrate_filter {
var $weight = 0;
var $op_weights = array();
function weight($op = NULL) {
if ($op && isset($this->op_weights[$op])) {
return $this->op_weights[$op];
}
return $this->weight;
}
function backup_settings_default() {
return array();
}
function backup_settings_form($settings) {
return array();
}
function backup_settings_form_validate($form, &$form_state) {
}
function backup_settings_form_submit($form, &$form_state) {
}
function restore_settings_default() {
return array();
}
function restore_settings_form($settings) {
return array();
}
function restore_settings_form_validate($form_values) {
}
function restore_settings_form_submit($form_values) {
return $form_values;
}
function file_types() {
return array();
}
function destinations() {
return array();
}
function backup($file, &$settings) {
return $file;
}
function restore($file, &$settings) {
return $file;
}
function pre_backup($source, $file, $settings) {
}
function post_backup($source, $file, $settings) {
}
}