Move theme preprocess function out of views_plugin_style_table.inc where it should...
[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 $items['admin/views/ajax/autocomplete/tag'] = $callback + array(
136 'page callback' => 'views_ui_autocomplete_tag',
137 );
138
139
140 // Generic ajax callback
141 // display specific parameters
142 $items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array(
143 'page callback' => 'views_ui_ajax_form',
144 'page arguments' => array(3, 4, 5),
145 );
146
147 return $items;
148 }
149
150 function views_ui_help($path, $arg) {
151 switch ($path) {
152 case 'admin/build/views/tools/convert':
153 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>';
154 }
155 }
156
157 /*
158 * Implementation of hook_perm()
159 */
160 function views_perm() {
161 return array('administer views');
162 }
163
164 function views_ui_theme() {
165 $path = drupal_get_path('module', 'views');
166 require_once "./$path/includes/admin.inc";
167
168 return array(
169 // edit a view
170 'views_ui_edit_view' => array(
171 'arguments' => array('view' => NULL),
172 'template' => 'views-ui-edit-view',
173 'path' => "$path/theme",
174 ),
175 'views_ui_edit_tab' => array(
176 'arguments' => array('view' => NULL, 'display' => NULL),
177 'template' => 'views-ui-edit-tab',
178 'path' => "$path/theme",
179 ),
180 'views_ui_edit_item' => array(
181 'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE),
182 'template' => 'views-ui-edit-item',
183 'path' => "$path/theme",
184 ),
185 'views_ui_rearrange_form' => array(
186 'arguments' => array('form' => NULL),
187 'file' => '/includes/admin.inc',
188 ),
189
190 // list views
191 'views_ui_list_views' => array(
192 'template' => 'views-ui-list-views',
193 'path' => "$path/theme",
194 ),
195 'views_ui_list_views_form' => array(
196 'file' => '/includes/admin.inc',
197 'arguments' => array('form' => NULL),
198 ),
199
200 // tab themes
201 'views_tabset' => array(
202 'arguments' => array('tabs' => NULL),
203 'file' => '/includes/tabs.inc',
204 ),
205 'views_tab' => array(
206 'arguments' => array('body' => NULL),
207 'file' => '/includes/tabs.inc',
208 ),
209
210 // On behalf of a plugin
211 'views_ui_style_plugin_table' => array(
212 'arguments' => array('form' => NULL),
213 'file' => 'includes/plugins.inc',
214 ),
215 );
216 }
217
218 /**
219 * Specialized menu callback to load a view either out of the cache or just
220 * load it.
221 */
222 function views_ui_cache_load($name) {
223 views_include('cache');
224 views_include('view');
225 $view = views_object_cache_get('view', $name);
226
227 if (empty($view)) {
228 $view = views_get_view($name);
229
230 if (!empty($view)) {
231 // Check to see if someone else is already editing this view.
232 global $user;
233 $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));
234 }
235 }
236
237 if (empty($view)) {
238 return FALSE;
239 }
240
241 else {
242 return $view;
243 }
244 }
245
246 function views_ui_check_lock($view) {
247
248 }
249
250 /**
251 * Specialized cache function to add a flag to our view, include an appropriate
252 * include, and cache more easily.
253 */
254 function views_ui_cache_set(&$view) {
255 if (!empty($view->locked)) {
256 drupal_set_message('Changes cannot be made to a locked view.', 'error');
257 return;
258 }
259 views_include('cache');
260 $view->changed = TRUE; // let any future object know that this view has changed.
261
262 // Unset handlers; we don't want to write these into the cache
263 unset($view->display_handler);
264 unset($view->current_display);
265 unset($view->default_display);
266 foreach (array_keys($view->display) as $id) {
267 unset($view->display[$id]->handler);
268 unset($view->display[$id]->default_display);
269 }
270 views_object_cache_set('view', $view->name, $view);
271 }
272
273
274 /**
275 * Specialized menu callback to load a view that is only a default
276 * view.
277 */
278 function views_ui_default_load($name) {
279 $view = views_get_view($name);
280 if ($view->type == t('Default')) {
281 return $view;
282 }
283
284 return FALSE;
285 }
286
287 /**
288 * Check to see if the incoming menu item is js capable or not.
289 */
290 function views_ui_js_load($js) {
291 if ($js == 'ajax') {
292 return TRUE;
293 }
294 return 0;
295 }