Oops, committed debugging message.
[project/views.git] / views_ui.module
CommitLineData
5a781272
EM
1<?php
2// $Id$
5a781272
EM
3/**
4 * @file views_ui.module
b9613702 5 * Provide structure for the administrative interface to Views.
5a781272
EM
6 */
7
455d2315
EM
8/*
9 * Implementation of hook_menu()
10 */
5a781272
EM
11function views_ui_menu() {
12 $items = array();
13
b9613702
EM
14 // Minor code reduction technique
15 $base = array(
5a781272
EM
16 'access callback' => 'user_access',
17 'access arguments' => array('administer views'),
b9613702
EM
18 'file' => 'includes/admin.inc',
19 );
20
ddf08198
EM
21 $callback = $base + array('type' => MENU_CALLBACK);
22
8dea0345
EM
23 $convert = array('file' => 'includes/convert.inc') + $base;
24
b9613702 25 $items['admin/build/views'] = $base + array(
649cf969 26 'title' => 'Views',
b9613702 27 'page callback' => 'views_ui_list_views',
649cf969 28 '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.',
5a781272
EM
29 'type' => MENU_NORMAL_ITEM
30 );
b9613702 31 $items['admin/build/views/list'] = $base + array(
649cf969 32 'title' => 'List',
5a781272 33 'page callback' => 'views_ui_list_views',
5a781272
EM
34 'type' => MENU_DEFAULT_LOCAL_TASK,
35 'weight' => '-1'
36 );
b9613702 37 $items['admin/build/views/add'] = $base + array(
649cf969 38 'title' => 'Add',
5a781272 39 'page callback' => 'views_ui_add_page',
5a781272
EM
40 'type' => MENU_LOCAL_TASK
41 );
b9613702 42 $items['admin/build/views/import'] = $base + array(
649cf969 43 'title' => 'Import',
1008b7ff
EM
44 'page callback' => 'drupal_get_form',
45 'page arguments' => array('views_ui_import_page'),
5a781272
EM
46 'type' => MENU_LOCAL_TASK
47 );
b9613702 48 $items['admin/build/views/tools'] = $base + array(
649cf969 49 'title' => 'Tools',
104a067d
EM
50 'page callback' => 'drupal_get_form',
51 'page arguments' => array('views_ui_admin_tools'),
5a781272
EM
52 'type' => MENU_LOCAL_TASK
53 );
8dea0345 54 $items['admin/build/views/tools/basic'] = $base + array(
649cf969 55 'title' => 'Basic',
8dea0345
EM
56 'page callback' => 'drupal_get_form',
57 'page arguments' => array('views_ui_admin_tools'),
58 'type' => MENU_DEFAULT_LOCAL_TASK,
59 'weight' => -10,
60 );
61
62 $items['admin/build/views/tools/convert'] = $convert + array(
649cf969
EM
63 'title' => 'Convert',
64 'description' => 'Convert stored Views 1 views.',
3fddb150 65 'page callback' => 'views_ui_admin_convert',
3fddb150 66 'type' => MENU_LOCAL_TASK,
8dea0345 67 'weight' => 1,
3fddb150 68 );
8dea0345 69 $items['admin/build/views1/delete'] = $convert + array(
649cf969 70 'title' => 'Delete view',
3fddb150
EM
71 'page callback' => 'drupal_get_form',
72 'page arguments' => array('views_ui_delete1_confirm', 4),
8dea0345 73 'type' => MENU_CALLBACK,
3fddb150 74 );
8dea0345 75 $items['admin/build/views1/convert'] = $convert + array(
649cf969 76 'title' => 'Convert view',
3fddb150
EM
77 'page callback' => 'views_ui_convert1',
78 'page arguments' => array(4),
8dea0345 79 'type' => MENU_CALLBACK,
3fddb150 80 );
8dea0345 81
24caaddc 82 $items['admin/build/views/delete/%views_ui_cache'] = $callback + array(
649cf969 83 'title' => 'Delete view',
5a781272 84 'page callback' => 'drupal_get_form',
24caaddc 85 'page arguments' => array('views_ui_delete_confirm', 4),
5a781272 86 );
6d634f78 87 $items['admin/build/views/break-lock/%views_ui_cache'] = $callback + array(
649cf969 88 'title' => 'Delete view',
6d634f78
EM
89 'page callback' => 'drupal_get_form',
90 'page arguments' => array('views_ui_break_lock_confirm', 4),
91 );
8dea0345
EM
92 $items['admin/build/views/export/%views_ui_cache'] = $callback + array(
93 'page callback' => 'drupal_get_form',
94 'page arguments' => array('views_ui_export_page', 4),
5795fe91 95 'type' => MENU_LOCAL_TASK
8dea0345
EM
96 );
97 $items['admin/build/views/clone/%views_ui_cache'] = $callback + array(
98 'page callback' => 'views_ui_clone_page',
99 'page arguments' => array(4),
5795fe91 100 'type' => MENU_LOCAL_TASK
8dea0345 101 );
3fddb150 102 $items['admin/build/views/enable/%views_ui_default'] = $callback + array(
1008b7ff
EM
103 'page callback' => 'views_ui_enable_page',
104 'page arguments' => array(4),
5a781272 105 );
3fddb150 106 $items['admin/build/views/disable/%views_ui_default'] = $callback + array(
1008b7ff
EM
107 'page callback' => 'views_ui_disable_page',
108 'page arguments' => array(4),
ddf08198 109 );
8dea0345
EM
110
111 // Many line items for editing a view.
112 $items['admin/build/views/edit/%views_ui_cache'] = $base + array(
649cf969 113 'title' => 'Edit',
8dea0345
EM
114 'page callback' => 'views_ui_edit_page',
115 'page arguments' => array(4),
116 'type' => MENU_LOCAL_TASK
1008b7ff 117 );
ddf08198 118 // lots of little edit form pieces.
e01ef45a
EM
119 $items['admin/build/views/%views_ui_js/analyze/%views_ui_cache'] = $callback + array(
120 'page callback' => 'views_ui_analyze_view',
121 'page arguments' => array(3, 5),
122 );
dc3ec4ee 123 $items['admin/build/views/%views_ui_js/details/%views_ui_cache'] = $callback + array(
ddf08198 124 'page callback' => 'views_ui_edit_details',
dc3ec4ee 125 'page arguments' => array(3, 5),
ddf08198 126 );
dc3ec4ee 127 $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
ddf08198 128 'page callback' => 'views_ui_add_display',
dc3ec4ee
EM
129 'page arguments' => array(3, 5),
130 );
e13e596d
EM
131 // Live preview
132 $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
133 'page callback' => 'views_ui_preview',
134 'page arguments' => array(3, 5),
135 );
06f6fd84 136
ebd86539 137 // autocompletes for handlers and such
312e3f6b
EM
138 $items['admin/views/ajax/autocomplete/tag'] = $callback + array(
139 'page callback' => 'views_ui_autocomplete_tag',
140 );
141
ebd86539 142
bd1728c3
EM
143 // Generic ajax callback
144 // display specific parameters
145 $items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array(
146 'page callback' => 'views_ui_ajax_form',
147 'page arguments' => array(3, 4, 5),
148 );
149
5a781272
EM
150 return $items;
151}
152
455d2315
EM
153/*
154 * Implementation of hook_help()
155 */
fdd15887 156function views_ui_help($path, $arg = '') {
586bef9b 157 switch ($path) {
8dea0345
EM
158 case 'admin/build/views/tools/convert':
159 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>';
586bef9b
EM
160 }
161}
162
5a781272 163/*
455d2315
EM
164 * Implementation of hook_theme()
165 */
74ea60f0 166function views_ui_theme() {
999b2e53 167 $path = drupal_get_path('module', 'views');
ac4c4385 168 require_once "./$path/includes/admin.inc";
999b2e53 169
74ea60f0 170 return array(
54fe4dd0 171 // edit a view
74ea60f0 172 'views_ui_edit_view' => array(
999b2e53
EM
173 'arguments' => array('view' => NULL),
174 'template' => 'views-ui-edit-view',
175 'path' => "$path/theme",
74ea60f0 176 ),
b7d23d7c
EM
177 'views_ui_edit_tab' => array(
178 'arguments' => array('view' => NULL, 'display' => NULL),
179 'template' => 'views-ui-edit-tab',
180 'path' => "$path/theme",
181 ),
182 'views_ui_edit_item' => array(
9489257b 183 'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE),
b7d23d7c
EM
184 'template' => 'views-ui-edit-item',
185 'path' => "$path/theme",
186 ),
3a69a04c 187 'views_ui_rearrange_form' => array(
999b2e53 188 'arguments' => array('form' => NULL),
fa14d543 189 'file' => 'includes/admin.inc',
3a69a04c 190 ),
54fe4dd0
EM
191
192 // list views
193 'views_ui_list_views' => array(
194 'template' => 'views-ui-list-views',
195 'path' => "$path/theme",
196 ),
197 'views_ui_list_views_form' => array(
fa14d543 198 'file' => 'includes/admin.inc',
54fe4dd0
EM
199 'arguments' => array('form' => NULL),
200 ),
201
202 // tab themes
74ea60f0 203 'views_tabset' => array(
999b2e53 204 'arguments' => array('tabs' => NULL),
fa14d543 205 'file' => 'includes/tabs.inc',
74ea60f0
EM
206 ),
207 'views_tab' => array(
999b2e53 208 'arguments' => array('body' => NULL),
fa14d543 209 'file' => 'includes/tabs.inc',
74ea60f0 210 ),
6b92ee49 211
54fe4dd0 212 // On behalf of a plugin
6b92ee49
EM
213 'views_ui_style_plugin_table' => array(
214 'arguments' => array('form' => NULL),
21a1e21d 215 'file' => 'includes/admin.inc',
6b92ee49 216 ),
74ea60f0
EM
217 );
218}
219
5a781272 220/**
b9613702
EM
221 * Specialized menu callback to load a view either out of the cache or just
222 * load it.
5a781272 223 */
b9613702
EM
224function views_ui_cache_load($name) {
225 views_include('cache');
226 views_include('view');
227 $view = views_object_cache_get('view', $name);
74ea60f0 228
b9613702 229 if (empty($view)) {
20aff9d4 230 $view = views_get_view($name);
6d634f78 231
7ae4dc41
EM
232 if (!empty($view)) {
233 // Check to see if someone else is already editing this view.
234 global $user;
f1ccc180 235 $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));
7ae4dc41 236 }
5a781272
EM
237 }
238
b9613702
EM
239 if (empty($view)) {
240 return FALSE;
5a781272
EM
241 }
242
b9613702
EM
243 else {
244 return $view;
58e4ed44 245 }
58e4ed44
EM
246}
247
f1ccc180
EM
248function views_ui_check_lock($view) {
249
250}
251
58e4ed44 252/**
6d634f78
EM
253 * Specialized cache function to add a flag to our view, include an appropriate
254 * include, and cache more easily.
255 */
256function views_ui_cache_set(&$view) {
257 if (!empty($view->locked)) {
d8b804e8 258 drupal_set_message(t('Changes cannot be made to a locked view.'), 'error');
6d634f78
EM
259 return;
260 }
261 views_include('cache');
262 $view->changed = TRUE; // let any future object know that this view has changed.
263
264 // Unset handlers; we don't want to write these into the cache
265 unset($view->display_handler);
266 unset($view->current_display);
267 unset($view->default_display);
268 foreach (array_keys($view->display) as $id) {
269 unset($view->display[$id]->handler);
270 unset($view->display[$id]->default_display);
271 }
272 views_object_cache_set('view', $view->name, $view);
273}
274
275
276/**
3fddb150
EM
277 * Specialized menu callback to load a view that is only a default
278 * view.
279 */
280function views_ui_default_load($name) {
281 $view = views_get_view($name);
282 if ($view->type == t('Default')) {
283 return $view;
284 }
285
286 return FALSE;
287}
288
289/**
dc3ec4ee
EM
290 * Check to see if the incoming menu item is js capable or not.
291 */
292function views_ui_js_load($js) {
293 if ($js == 'ajax') {
294 return TRUE;
295 }
296 return 0;
297}