View source
<?php
define('FEEDS_TAMPER_UI_FEEDS_BASE', 'admin/build/feeds');
define('FEEDS_TAMPER_UI_BASE', FEEDS_TAMPER_UI_FEEDS_BASE . '/tamper');
function feeds_tamper_ui_help($path, $arg) {
switch ($path) {
case FEEDS_TAMPER_UI_BASE . '/list/%':
$importer = feeds_importer($arg[5]);
$link = l(t('mapping'), FEEDS_TAMPER_UI_FEEDS_BASE . '/edit/' . $importer->id . '/mapping');
return '<p>' . t('Configure plugins to modify Feeds data before it gets saved. Each !mapping can be manipulated individually.', array(
'!mapping' => $link,
)) . '</p>';
}
}
function feeds_tamper_ui_menu() {
$defaults = array(
'page callback' => 'drupal_get_form',
'access callback' => 'feeds_tamper_access',
'access arguments' => array(
5,
),
'file' => 'feeds_tamper_ui.admin.inc',
'title arguments' => array(
5,
),
'type' => MENU_CALLBACK,
);
$items = array();
$items[FEEDS_TAMPER_UI_BASE . '/list/%feeds_importer'] = array(
'title callback' => 'feeds_tamper_ui_main_title',
'page arguments' => array(
'feeds_tamper_ui_list_form',
5,
),
) + $defaults;
$items[FEEDS_TAMPER_UI_BASE . '/add/%feeds_importer/%feeds_tamper_ui_source'] = array(
'title callback' => 'feeds_tamper_ui_add_title',
'title arguments' => array(
6,
),
'page arguments' => array(
'feeds_tamper_ui_add_plugin_form',
5,
6,
),
) + $defaults;
$items[FEEDS_TAMPER_UI_BASE . '/edit/%feeds_tamper_plugin_instance'] = array(
'title callback' => 'feeds_tamper_ui_edit_title',
'page arguments' => array(
'feeds_tamper_ui_edit_plugin_form',
5,
),
'access arguments' => array(
NULL,
5,
),
) + $defaults;
$items[FEEDS_TAMPER_UI_BASE . '/delete/%feeds_tamper_plugin_instance'] = array(
'title callback' => 'feeds_tamper_ui_delete_title',
'page arguments' => array(
'feeds_tamper_ui_delete_form',
5,
),
'access arguments' => array(
NULL,
5,
),
) + $defaults;
$items['feeds_tamper/js'] = array(
'page callback' => 'feeds_tamper_ui_js',
'access callback' => TRUE,
'file' => 'feeds_tamper_ui.admin.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function feeds_tamper_ui_theme() {
return array(
'feeds_tamper_ui_list_form' => array(
'arguments' => array(
'form' => NULL,
),
),
);
}
function feeds_tamper_plugin_instance_load($instance_id) {
return feeds_tamper_load_instance($instance_id);
}
function feeds_tamper_ui_source_load($source) {
return pack('H*', $source);
}
function feeds_tamper_ui_main_title($importer) {
return t('Tamper plugins: @name', array(
'@name' => $importer->config['name'],
));
}
function feeds_tamper_ui_add_title($source) {
return t('Add plugin to: @source', array(
'@source' => $source,
));
}
function feeds_tamper_ui_edit_title($instance) {
if ($instance->export_type == EXPORT_IN_DATABASE) {
return t('Edit: @id', array(
'@id' => $instance->description,
));
}
return t('Override: @id', array(
'@id' => $instance->description,
));
}
function feeds_tamper_ui_delete_title($instance) {
if ($instance->export_type == EXPORT_IN_DATABASE) {
return t('Delete plugin: @id', array(
'@id',
$instance->id,
));
}
return t('Revert plugin: @id', array(
'@id',
$instance->id,
));
}
function feeds_tamper_ui_form_feeds_ui_overview_form_alter(&$form, &$form_state) {
if (!empty($form['enabled'])) {
foreach ($form['enabled'] as $id => &$table) {
if (feeds_tamper_access($id)) {
$table['operations']['#value'] .= ' | ' . l(t('Tamper'), FEEDS_TAMPER_UI_BASE . '/list/' . $id);
}
}
}
}
function feeds_tamper_ui_form_feeds_ui_mapping_form_alter(&$form, &$form_state) {
if (feeds_tamper_access($form['#importer'])) {
$form['help']['#value'] .= l(t('Configure Feeds Tamper'), FEEDS_TAMPER_UI_BASE . '/list/' . $form['#importer']->id);
}
}
function feeds_tamper_ui_source_name($instance) {
if (!is_object($instance)) {
$instance = feeds_tamper_get_plugin($instance);
}
$importer = feeds_importer($instance->importer);
$sources = $importer->parser
->getMappingSources();
return !empty($sources[$instance->source]['name']) ? check_plain($sources[$instance->source]['name']) : check_plain($instance->source);
}