#265910: Restore "access all views" permission from Views 1.
[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 'type' => MENU_LOCAL_TASK
93 );
94 $items['admin/build/views/clone/%views_ui_cache'] = $callback + array(
95 'page callback' => 'views_ui_clone_page',
96 'page arguments' => array(4),
97 'type' => MENU_LOCAL_TASK
98 );
99 $items['admin/build/views/enable/%views_ui_default'] = $callback + array(
100 'page callback' => 'views_ui_enable_page',
101 'page arguments' => array(4),
102 );
103 $items['admin/build/views/disable/%views_ui_default'] = $callback + array(
104 'page callback' => 'views_ui_disable_page',
105 'page arguments' => array(4),
106 );
107
108 // Many line items for editing a view.
109 $items['admin/build/views/edit/%views_ui_cache'] = $base + array(
110 'title' => 'Edit',
111 'page callback' => 'views_ui_edit_page',
112 'page arguments' => array(4),
113 'type' => MENU_LOCAL_TASK
114 );
115 // lots of little edit form pieces.
116 $items['admin/build/views/%views_ui_js/analyze/%views_ui_cache'] = $callback + array(
117 'page callback' => 'views_ui_analyze_view',
118 'page arguments' => array(3, 5),
119 );
120 $items['admin/build/views/%views_ui_js/details/%views_ui_cache'] = $callback + array(
121 'page callback' => 'views_ui_edit_details',
122 'page arguments' => array(3, 5),
123 );
124 $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
125 'page callback' => 'views_ui_add_display',
126 'page arguments' => array(3, 5),
127 );
128 // Live preview
129 $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
130 'page callback' => 'views_ui_preview',
131 'page arguments' => array(3, 5),
132 );
133
134 // autocompletes for handlers and such
135 // Path is not admin/build/views due to menu complications with the wildcards from
136 // the generic ajax callback.
137 $items['admin/views/ajax/autocomplete/user'] = $callback + array(
138 'page callback' => 'views_ui_autocomplete_user',
139 );
140 $items['admin/views/ajax/autocomplete/tag'] = $callback + array(
141 'page callback' => 'views_ui_autocomplete_tag',
142 );
143
144
145 // Generic ajax callback
146 // display specific parameters
147 $items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array(
148 'page callback' => 'views_ui_ajax_form',
149 'page arguments' => array(3, 4, 5),
150 );
151
152 return $items;
153 }
154
155 function views_ui_help($path, $arg) {
156 switch ($path) {
157 case 'admin/build/views/tools/convert':
158 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>';
159 }
160 }
161
162 /*
163 * Implementation of hook_perm()
164 */
165 function views_perm() {
166 return array('administer views');
167 }
168
169 function views_ui_theme() {
170 $path = drupal_get_path('module', 'views');
171 require_once "./$path/includes/admin.inc";
172
173 return array(
174 // edit a view
175 'views_ui_edit_view' => array(
176 'arguments' => array('view' => NULL),
177 'template' => 'views-ui-edit-view',
178 'path' => "$path/theme",
179 ),
180 'views_ui_edit_tab' => array(
181 'arguments' => array('view' => NULL, 'display' => NULL),
182 'template' => 'views-ui-edit-tab',
183 'path' => "$path/theme",
184 ),
185 'views_ui_edit_item' => array(
186 'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL),
187 'template' => 'views-ui-edit-item',
188 'path' => "$path/theme",
189 ),
190 'views_ui_rearrange_form' => array(
191 'arguments' => array('form' => NULL),
192 'file' => '/includes/admin.inc',
193 ),
194
195 // list views
196 'views_ui_list_views' => array(
197 'template' => 'views-ui-list-views',
198 'path' => "$path/theme",
199 ),
200 'views_ui_list_views_form' => array(
201 'file' => '/includes/admin.inc',
202 'arguments' => array('form' => NULL),
203 ),
204
205 // tab themes
206 'views_tabset' => array(
207 'arguments' => array('tabs' => NULL),
208 'file' => '/includes/tabs.inc',
209 ),
210 'views_tab' => array(
211 'arguments' => array('body' => NULL),
212 'file' => '/includes/tabs.inc',
213 ),
214
215 // On behalf of a plugin
216 'views_ui_style_plugin_table' => array(
217 'arguments' => array('form' => NULL),
218 ),
219 );
220 }
221
222 /**
223 * Specialized menu callback to load a view either out of the cache or just
224 * load it.
225 */
226 function views_ui_cache_load($name) {
227 views_include('cache');
228 views_include('view');
229 $view = views_object_cache_get('view', $name);
230
231 if (empty($view)) {
232 $view = views_get_view($name);
233
234 if (!empty($view)) {
235 // Check to see if someone else is already editing this view.
236 global $user;
237 $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));
238 }
239 }
240
241 if (empty($view)) {
242 return FALSE;
243 }
244
245 else {
246 return $view;
247 }
248 }
249
250 function views_ui_check_lock($view) {
251
252 }
253
254 /**
255 * Specialized cache function to add a flag to our view, include an appropriate
256 * include, and cache more easily.
257 */
258 function views_ui_cache_set(&$view) {
259 if (!empty($view->locked)) {
260 drupal_set_message('Changes cannot be made to a locked view.', 'error');
261 return;
262 }
263 views_include('cache');
264 $view->changed = TRUE; // let any future object know that this view has changed.
265
266 // Unset handlers; we don't want to write these into the cache
267 unset($view->display_handler);
268 unset($view->current_display);
269 unset($view->default_display);
270 foreach (array_keys($view->display) as $id) {
271 unset($view->display[$id]->handler);
272 unset($view->display[$id]->default_display);
273 }
274 views_object_cache_set('view', $view->name, $view);
275 }
276
277
278 /**
279 * Specialized menu callback to load a view that is only a default
280 * view.
281 */
282 function views_ui_default_load($name) {
283 $view = views_get_view($name);
284 if ($view->type == t('Default')) {
285 return $view;
286 }
287
288 return FALSE;
289 }
290
291 /**
292 * Check to see if the incoming menu item is js capable or not.
293 */
294 function views_ui_js_load($js) {
295 if ($js == 'ajax') {
296 return TRUE;
297 }
298 return 0;
299 }