| 1 |
<?php |
<?php |
| 2 |
// $Id: feedapi_mapper.admin.inc,v 1.1.2.10 2009/09/18 12:52:33 aronnovak Exp $ |
// $Id: feedapi_mapper.admin.inc,v 1.1.2.11 2009/09/28 16:53:44 alexb Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Administration-related functions for FeedAPI Mapper |
* Administration-related functions for FeedAPI Mapper |
| 110 |
* Submission callback for feedapi_mapper_delete_form. |
* Submission callback for feedapi_mapper_delete_form. |
| 111 |
*/ |
*/ |
| 112 |
function feedapi_mapper_delete_form_submit($form, &$form_state) { |
function feedapi_mapper_delete_form_submit($form, &$form_state) { |
| 113 |
$param = isset($form['#node']->nid) && _feedapi_mapper_is_overridden($form['#node']->nid) ? $form['#node']->nid : $form['#node']->type; |
$param = isset($form['#node']->nid) && _feedapi_mapper_scope($form['#node']->nid) ? $form['#node']->nid : $form['#node']->type; |
| 114 |
$node = new stdClass(); |
$node = new stdClass(); |
| 115 |
$field = is_numeric($param) ? 'nid' : 'type'; |
$field = is_numeric($param) ? 'nid' : 'type'; |
| 116 |
$node->{$field} = $param; |
$node->{$field} = $param; |
| 160 |
$node->type = str_replace('-', '_', $param); |
$node->type = str_replace('-', '_', $param); |
| 161 |
$path = 'admin/content/node-type/'. $param .'/map'; |
$path = 'admin/content/node-type/'. $param .'/map'; |
| 162 |
} |
} |
| 163 |
elseif (!_feedapi_mapper_is_overridden($param)) { |
elseif (!_feedapi_mapper_scope($param)) { |
| 164 |
$node = node_load($param); |
$node = node_load($param); |
| 165 |
$path = "node/{$param}/map"; |
$path = "node/{$param}/map"; |
| 166 |
$param = $node->type; |
$param = $node->type; |
| 184 |
$form['#redirect'] = "node/{$feed_node->nid}/map"; |
$form['#redirect'] = "node/{$feed_node->nid}/map"; |
| 185 |
|
|
| 186 |
return confirm_form($form, |
return confirm_form($form, |
| 187 |
t('Use content-type default?'), |
t('Use content-type settings?'), |
| 188 |
"node/{$feed_node->nid}/map", |
"node/{$feed_node->nid}/map", |
| 189 |
t('Are you sure you would like to delete this mapping and fall back to the !default? This action cannot be undone.', array('!default' => l(t('content-type default'), 'admin/content/node-type/'. str_replace('_', '-', $feed_node->type) .'/map'))), |
t('Are you sure you would like to delete this mapping and fall back to the !default? This action cannot be undone.', array('!default' => l(t('content-type settings'), 'admin/content/node-type/'. str_replace('_', '-', $feed_node->type) .'/map'))), |
| 190 |
t('Delete and use default'), |
t('Delete and use content-type settings'), |
| 191 |
t('Cancel') |
t('Cancel') |
| 192 |
); |
); |
| 193 |
} |
} |
| 201 |
} |
} |
| 202 |
|
|
| 203 |
/** |
/** |
| 204 |
* Form callback confirmation form for override mapping. |
* Form callback confirmation form for restrict mapping to the given node. |
| 205 |
*/ |
*/ |
| 206 |
function feedapi_mapper_override_form($form_state, $feed_node) { |
function feedapi_mapper_restrict_form($form_state, $feed_node) { |
| 207 |
$form = array(); |
$form = array(); |
| 208 |
$form['#node'] = $feed_node; |
$form['#node'] = $feed_node; |
| 209 |
$form['#redirect'] = "node/{$feed_node->nid}/map"; |
$form['#redirect'] = "node/{$feed_node->nid}/map"; |
| 210 |
|
|
| 211 |
return confirm_form($form, |
return confirm_form($form, |
| 212 |
t('Override?'), |
t('Change to per-node?'), |
| 213 |
"node/{$feed_node->nid}/map", |
"node/{$feed_node->nid}/map", |
| 214 |
t('Would you like to override the content-type defaults?'), |
t('Would you like to apply the mapping to the feed "!title" only?', array('!title' => $feed_node->title)), |
| 215 |
t('Override'), |
t('Change to per-node'), |
| 216 |
t('Cancel') |
t('Cancel') |
| 217 |
); |
); |
| 218 |
} |
} |
| 219 |
|
|
| 220 |
/** |
/** |
| 221 |
* Submission callback for feedapi_mapper_override_form. |
* Submission callback for feedapi_mapper_restrict_form. |
| 222 |
*/ |
*/ |
| 223 |
function feedapi_mapper_override_form_submit($form, &$form_state) { |
function feedapi_mapper_restrict_form_submit($form, &$form_state) { |
| 224 |
$mapping = feedapi_mapper_load_mapping($form['#node']); |
$mapping = feedapi_mapper_load_mapping($form['#node']); |
| 225 |
feedapi_mapper_save_mapping($form['#node']->nid, $mapping); |
feedapi_mapper_save_mapping($form['#node']->nid, $mapping); |
| 226 |
} |
} |
| 273 |
} |
} |
| 274 |
$form['#mapping'] = $mapping; |
$form['#mapping'] = $mapping; |
| 275 |
|
|
| 276 |
// Override settings: if theis is a node we are on and there is no mapping at all, |
// Scope settings: if there is is a node we are on and there is no mapping at all, |
| 277 |
// we are operating on the content-type defaults. If not we are overriding. |
// we are operating on the content-type defaults. If not it's per-node. |
| 278 |
if ($feed_node->nid && _feedapi_mapper_is_overridden($feed_node->nid)) { |
if ($feed_node->nid && _feedapi_mapper_scope($feed_node->nid)) { |
| 279 |
$override = t('This mapping is specific to this feed node.') .' '. l(t('Use content-type default.'), 'node/'. $feed_node->nid .'/map/default'); |
$scope = t('This mapping is specific to this feed node.'); |
| 280 |
$form['#override'] = TRUE; |
$scope_op = l(t('Use content-type mapping'), 'node/'. $feed_node->nid .'/map/default'); |
| 281 |
|
$form['#scope'] = TRUE; |
| 282 |
} |
} |
| 283 |
elseif (isset($feed_node->nid)) { |
elseif (isset($feed_node->nid)) { |
| 284 |
$override = t('This mapping is the standard content-type mapping. Any changes will affect all feeds with the same content-type.') .' '. l(t('Override.'), 'node/'. $feed_node->nid .'/map/override'); |
$scope = t('This mapping applies to all content-types. Any changes will affect all feeds with the same content-type.'); |
| 285 |
$form['#override'] = FALSE; |
$scope_op = l(t('Change to per node'), 'node/'. $feed_node->nid .'/map/restrict'); |
| 286 |
|
$form['#scope'] = FALSE; |
| 287 |
} |
} |
| 288 |
|
|
| 289 |
if ($mapping['export_type'] === EXPORT_IN_DATABASE) { |
if ($mapping['export_type'] === EXPORT_IN_DATABASE) { |
| 290 |
$status = t('Status: normal'); |
$status = t('Normal (This mapping is defined in the database).'); |
| 291 |
|
$status_op = ' '; |
| 292 |
} |
} |
| 293 |
if ($mapping['export_type'] === EXPORT_IN_CODE) { |
if ($mapping['export_type'] === EXPORT_IN_CODE) { |
| 294 |
$status = t('Status: default'); |
$status = t('Default (This mapping is defined in code).'); |
| 295 |
|
$status_op = ' '; |
| 296 |
} |
} |
| 297 |
if ($mapping['export_type'] === (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) { |
if ($mapping['export_type'] === (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) { |
| 298 |
$destination = isset($feed_node->nid) ? "node/{$feed_node->nid}/map" : "admin/content/node-type/{$feed_node->type}/map"; |
$destination = isset($feed_node->nid) ? "node/{$feed_node->nid}/map" : "admin/content/node-type/{$feed_node->type}/map"; |
| 299 |
$status = t('Status: overridden - ') . l(t('revert.'), 'admin/content/node-type/'. str_replace('_', '-', $feed_node->type) .'/map/revert', array('query' => array('destination' => $destination))); |
$status = t('Overridden (There is a default mapping defined in code but it is overridden in the database)'); |
| 300 |
|
$status_op = l(t('Revert'), 'admin/content/node-type/'. str_replace('_', '-', $feed_node->type) .'/map/revert', array('query' => array('destination' => $destination))); |
| 301 |
} |
} |
| 302 |
|
|
| 303 |
$form['override'] = array( |
$form['status_scope'] = array( |
| 304 |
'#value' => $override, |
'#type' => 'fieldset', |
| 305 |
|
'#title' => t('Status and scope'), |
| 306 |
|
); |
| 307 |
|
$rows = array(); |
| 308 |
|
$rows[] = array( |
| 309 |
|
'<strong>'. t('Status') .'</strong>', $status, $status_op, |
| 310 |
); |
); |
| 311 |
$form['revert'] = array( |
$rows[] = array( |
| 312 |
'#value' => '<div class="export-status"><strong>'. $status .'</strong></div>', |
'<strong>'. t('Scope') .'</strong>', $scope, $scope_op, |
| 313 |
); |
); |
| 314 |
|
$form['status_scope']['value']['#value'] = theme('table', array(), $rows); |
| 315 |
|
|
| 316 |
// Create a placeholder for mapping form elements. This will be populated in |
// Create a placeholder for mapping form elements. This will be populated in |
| 317 |
// theme_feedapi_mapper_form(). |
// theme_feedapi_mapper_form(). |
| 408 |
* Submit hook. |
* Submit hook. |
| 409 |
*/ |
*/ |
| 410 |
function feedapi_mapper_form_submit($form, &$form_state) { |
function feedapi_mapper_form_submit($form, &$form_state) { |
| 411 |
$param = ($form['#node']->nid && $form['#override']) ? $form['#node']->nid : $form['#node']->type; |
$param = ($form['#node']->nid && $form['#scope']) ? $form['#node']->nid : $form['#node']->type; |
| 412 |
feedapi_mapper_add_mapping($param, $form_state['values']['source'], $form_state['values']['target'], FALSE); |
feedapi_mapper_add_mapping($param, $form_state['values']['source'], $form_state['values']['target'], FALSE); |
| 413 |
} |
} |
| 414 |
|
|
| 417 |
*/ |
*/ |
| 418 |
function feedapi_mapper_export_page($form_state, $param) { |
function feedapi_mapper_export_page($form_state, $param) { |
| 419 |
if (is_object($param)) { |
if (is_object($param)) { |
| 420 |
if (_feedapi_mapper_is_overridden($param->nid)) { |
if (_feedapi_mapper_scope($param->nid)) { |
| 421 |
drupal_set_message(t('Only per content-type mappings can be exported.'), 'warning'); |
drupal_set_message(t('Only per content-type mappings can be exported.'), 'warning'); |
| 422 |
drupal_goto("node/{$param->nid}/map"); |
drupal_goto("node/{$param->nid}/map"); |
| 423 |
} |
} |