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