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