summaryrefslogtreecommitdiffstats
path: root/views_ui.module
blob: fbb581c16c3b61da685e51843db4d6e9ccfb5253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
/**
 * @file views_ui.module
 * Provide structure for the administrative interface to Views.
 */

/*
 * Implementation of hook_menu()
 */
function views_ui_menu() {
  $items = array();

  // Minor code reduction technique
  $base = array(
    'access callback' => 'user_access',
    'access arguments' => array('administer views'),
    'file' => 'includes/admin.inc',
  );

  $callback = $base + array('type' => MENU_CALLBACK);

  $convert = array('file' => 'includes/convert.inc') + $base;

  $items['admin/build/views'] = $base + array(
    'title' => 'Views',
    'page callback' => 'views_ui_list_views',
    'description' => 'Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.',
    'type' => MENU_NORMAL_ITEM
  );
  $items['admin/build/views/list'] = $base + array(
    'title' => 'List',
    'page callback' => 'views_ui_list_views',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => '-1'
  );
  $items['admin/build/views/add'] = $base + array(
    'title' => 'Add',
    'page callback' => 'views_ui_add_page',
    'type' => MENU_LOCAL_TASK
  );
  $items['admin/build/views/import'] = array(
    'title' => 'Import',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_import_page'),
    'access callback' => 'views_import_access',
    'type' => MENU_LOCAL_TASK
  ) + $base;
  $items['admin/build/views/tools'] = $base + array(
    'title' => 'Tools',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_admin_tools'),
    'type' => MENU_LOCAL_TASK
  );
  $items['admin/build/views/tools/basic'] = $base + array(
    'title' => 'Basic',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_admin_tools'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );

  $items['admin/build/views/tools/convert'] = $convert + array(
    'title' => 'Convert',
    'description' => 'Convert stored Views 1 views.',
    'page callback' => 'views_ui_admin_convert',
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  );
  $items['admin/build/views1/delete'] = $convert + array(
    'title' => 'Delete view',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_delete1_confirm', 4),
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/views1/convert'] = $convert + array(
    'title' => 'Convert view',
    'page callback' => 'views_ui_convert1',
    'page arguments' => array(4),
    'type' => MENU_CALLBACK,
  );

  $items['admin/build/views/delete/%views_ui_cache'] = $callback + array(
    'title' => 'Delete view',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_delete_confirm', 4),
  );
  $items['admin/build/views/break-lock/%views_ui_cache'] = $callback + array(
    'title' => 'Delete view',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_break_lock_confirm', 4),
  );
  $items['admin/build/views/export/%views_ui_cache'] = $callback + array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('views_ui_export_page', 4),
    'type' => MENU_LOCAL_TASK
  );
  $items['admin/build/views/clone/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_clone_page',
    'page arguments' => array(4),
    'type' => MENU_LOCAL_TASK
  );
  $items['admin/build/views/enable/%views_ui_default'] = $callback + array(
    'page callback' => 'views_ui_enable_page',
    'page arguments' => array(4),
  );
  $items['admin/build/views/disable/%views_ui_default'] = $callback + array(
    'page callback' => 'views_ui_disable_page',
    'page arguments' => array(4),
  );

  // Many line items for editing a view.
  $items['admin/build/views/edit/%views_ui_cache'] = $base + array(
    'title' => 'Edit',
    'page callback' => 'views_ui_edit_page',
    'page arguments' => array(4),
    'type' => MENU_LOCAL_TASK
  );
  // lots of little edit form pieces.
  $items['admin/build/views/%views_ui_js/analyze/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_analyze_view',
    'page arguments' => array(3, 5),
  );
  $items['admin/build/views/%views_ui_js/reorder-displays/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_reorder_view',
    'page arguments' => array(3, 5),
  );
  $items['admin/build/views/%views_ui_js/human_name/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_edit_details',
    'page arguments' => array('human_name', 3, 5),
  );
  $items['admin/build/views/%views_ui_js/tag/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_edit_details',
    'page arguments' => array('tag', 3, 5),
  );
  $items['admin/build/views/%views_ui_js/description/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_edit_details',
    'page arguments' => array('description', 3, 5),
  );
  $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_add_display',
    'page arguments' => array(3, 5),
  );
    $items['admin/build/views/%views_ui_js/clone-display/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_clone_display',
    'page arguments' => array(3, 5, 6),
  );
  // Live preview
  $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_preview',
    'page arguments' => array(3, 5),
  );

  // autocompletes for handlers and such
  $items['admin/views/ajax/autocomplete/tag'] = $callback + array(
    'page callback' => 'views_ui_autocomplete_tag',
  );


  // Generic ajax callback
  // display specific parameters
  $items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array(
    'page callback' => 'views_ui_ajax_form',
    'page arguments' => array(3, 4, 5),
  );

  return $items;
}

/*
 * Implementation of hook_help()
 */
function views_ui_help($path, $arg = '') {
  switch ($path) {
    case 'admin/build/views/tools/convert':
      return '<p>' . t('The converter will make a best-effort attempt to convert a Views 1 view to Views 2. This conversion is not reliable; you will very likely have to make adjustments to your view to get it to match. You can import Views 1 views through the normal Import tab.') . '</p>';
  }
}

/*
 * Implementation of hook_theme()
 */
function views_ui_theme() {
  $path = drupal_get_path('module', 'views');
  require_once "./$path/includes/admin.inc";

  return array(
    // edit a view
    'views_ui_edit_view' => array(
      'arguments' => array('view' => NULL),
      'template' => 'views-ui-edit-view',
      'path' => "$path/theme",
    ),
    'views_ui_edit_tab' => array(
      'arguments' => array('view' => NULL, 'display' => NULL),
      'template' => 'views-ui-edit-tab',
      'path' => "$path/theme",
    ),
    'views_ui_edit_item' => array(
      'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE),
      'template' => 'views-ui-edit-item',
      'path' => "$path/theme",
    ),
    'views_ui_rearrange_form' => array(
      'arguments' => array('form' => NULL),
      'file' => 'includes/admin.inc',
    ),
    'views_ui_rearrange_filter_form' => array(
      'arguments' => array('form' => NULL),
      'file' => 'includes/admin.inc',
    ),

    // list views
    'views_ui_list_views' => array(
      'template' => 'views-ui-list-views',
      'path' => "$path/theme",
    ),
    'views_ui_list_views_form' => array(
      'file' => 'includes/admin.inc',
      'arguments' => array('form' => NULL),
    ),

    // tab themes
    'views_tabset' => array(
      'arguments' => array('tabs' => NULL),
      'file' => 'includes/tabs.inc',
    ),
    'views_tab' => array(
      'arguments' => array('body' => NULL),
      'file' => 'includes/tabs.inc',
    ),
    'views_ui_reorder_displays_form' => array(
      'arguments' => array('form' => NULL),
      'file' => 'includes/admin.inc',
    ),


    // On behalf of a plugin
    'views_ui_style_plugin_table' => array(
      'arguments' => array('form' => NULL),
      'file' => 'includes/admin.inc',
    ),
  );
}

/**
 * Specialized menu callback to load a view either out of the cache or just
 * load it.
 */
function views_ui_cache_load($name) {
  views_include('cache');
  views_include('view');
  $view = views_object_cache_get('view', $name);

  if (empty($view)) {
    $view = views_get_view($name);

    if (!empty($view)) {
      // Check to see if someone else is already editing this view.
      global $user;
      $view->locked = db_fetch_object(db_query("SELECT s.uid, v.updated FROM {views_object_cache} v INNER JOIN {sessions}  s ON v.sid = s.sid WHERE s.sid != '%s' and v.name = '%s' and v.obj = 'view' ORDER BY v.updated ASC", session_id(), $view->name));
      // Set a flag to indicate that this view is being edited.
      // This flag will be used e.g. to determine whether strings
      // should be localized.
      $view->editing = TRUE;
    }
  }

  if (empty($view)) {
    return FALSE;
  }

  else {
    return $view;
  }
}

function views_ui_check_lock($view) {

}

/**
 * Specialized cache function to add a flag to our view, include an appropriate
 * include, and cache more easily.
 */
function views_ui_cache_set(&$view) {
  if (!empty($view->locked)) {
    drupal_set_message(t('Changes cannot be made to a locked view.'), 'error');
    return;
  }
  views_include('cache');
  $view->changed = TRUE; // let any future object know that this view has changed.

  // Unset handlers; we don't want to write these into the cache
  unset($view->display_handler);
  unset($view->current_display);
  unset($view->default_display);
  $view->query = NULL;
  foreach (array_keys($view->display) as $id) {
    unset($view->display[$id]->handler);
    unset($view->display[$id]->default_display);
  }
  views_object_cache_set('view', $view->name, $view);
}


/**
 * Specialized menu callback to load a view that is only a default
 * view.
 */
function views_ui_default_load($name) {
  $view = views_get_view($name);
  if ($view->type == t('Default')) {
    return $view;
  }

  return FALSE;
}

/**
 * Check to see if the incoming menu item is js capable or not.
 */
function views_ui_js_load($js) {
  if ($js == 'ajax') {
    return TRUE;
  }
  return 0;
}