node_export_features_ui.module 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @file
  4. * Node Export Features UI main module file
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function node_export_features_ui_menu() {
  10. $items = array();
  11. $items['admin/config/content/node_export/features'] = array(
  12. 'access arguments' => array('administer site configuration'),
  13. 'page callback' => 'drupal_get_form',
  14. 'page arguments' => array('node_export_features_ui_settings'),
  15. 'title' => 'Features Configuration',
  16. 'description' => 'Configure filters for nodes available to be exported by node export features',
  17. 'file' => 'node_export_features_ui.pages.inc',
  18. 'type' => MENU_LOCAL_TASK,
  19. 'weight' => 10,
  20. );
  21. return $items;
  22. }
  23. /**
  24. * Implements hook_query_alter().
  25. */
  26. function node_export_features_ui_query_alter(QueryAlterableInterface $query) {
  27. if ($query->hasTag('node_export_features')) {
  28. $range = variable_get('node_export_features_ui_range', 250);
  29. $types = variable_get('node_export_features_ui_content_types', array());
  30. $status = variable_get('node_export_features_ui_status', 0);
  31. $promote = variable_get('node_export_features_ui_promote', 0);
  32. $sticky = variable_get('node_export_features_ui_sticky', 0);
  33. $title = trim(variable_get('node_export_features_ui_title', ''));
  34. $uuids = node_export_features_ui_textarea_to_array(variable_get('node_export_features_ui_uuids', ''));
  35. // Add in the specified conditions.
  36. if ( $range ) {
  37. $query->range(0, $range);
  38. }
  39. if ( ! empty($types) ) {
  40. $query->condition('type', $types, 'IN');
  41. }
  42. if ( $status ) {
  43. $query->condition('status', $status-1);
  44. }
  45. if ( $promote ) {
  46. $query->condition('promote', $promote-1);
  47. }
  48. if ( $sticky ) {
  49. $query->condition('sticky', $sticky-1);
  50. }
  51. if ( $title ) {
  52. $query->condition('title', $title, 'LIKE');
  53. }
  54. if ( ! empty($uuids) ) {
  55. $query->condition('uuid', $uuids, 'IN');
  56. }
  57. }
  58. }
  59. /**
  60. * Utility function to convert a text area into a array of trimmed non-blank lines.
  61. *
  62. * @param string $area
  63. * The text area value to parse.
  64. * @return array
  65. * The parsed array of non-blank trimmed lines found in the area.
  66. * An empty array is returned if no information found.
  67. */
  68. function node_export_features_ui_textarea_to_array( $area ) {
  69. $area = trim($area);
  70. $results = array();
  71. if ( $area ) {
  72. $lines = explode("\r\n", $area);
  73. foreach ( $lines as $key => $value ) {
  74. $result = trim($value);
  75. if ( $result ) {
  76. $results[] = $result;
  77. }
  78. }
  79. }
  80. return $results;
  81. }