Improvements to Views 1 converter
[project/views.git] / views_ui.module
1 <?php
2 // $Id$
3
4 /**
5 * @file views_ui.module
6 *
7 * Provide structure for the administrative interface to Views.
8 */
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' => t('Views'),
26 'page callback' => 'views_ui_list_views',
27 'description' => t('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' => t('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' => t('Add'),
38 'page callback' => 'views_ui_add_page',
39 'type' => MENU_LOCAL_TASK
40 );
41 $items['admin/build/views/import'] = $base + array(
42 'title' => t('Import'),
43 'page callback' => 'drupal_get_form',
44 'page arguments' => array('views_ui_import_page'),
45 'type' => MENU_LOCAL_TASK
46 );
47 $items['admin/build/views/tools'] = $base + array(
48 'title' => t('Tools'),
49 'page callback' => 'views_ui_admin_tools',
50 'type' => MENU_LOCAL_TASK
51 );
52 $items['admin/build/views/tools/basic'] = $base + array(
53 'title' => t('Basic'),
54 'page callback' => 'drupal_get_form',
55 'page arguments' => array('views_ui_admin_tools'),
56 'type' => MENU_DEFAULT_LOCAL_TASK,
57 'weight' => -10,
58 );
59
60 $items['admin/build/views/tools/convert'] = $convert + array(
61 'title' => t('Convert'),
62 'description' => t('Convert stored Views 1 views.'),
63 'page callback' => 'views_ui_admin_convert',
64 'type' => MENU_LOCAL_TASK,
65 'weight' => 1,
66 );
67 $items['admin/build/views1/delete'] = $convert + array(
68 'title' => t('Delete view'),
69 'page callback' => 'drupal_get_form',
70 'page arguments' => array('views_ui_delete1_confirm', 4),
71 'type' => MENU_CALLBACK,
72 );
73 $items['admin/build/views1/convert'] = $convert + array(
74 'title' => t('Convert view'),
75 'page callback' => 'views_ui_convert1',
76 'page arguments' => array(4),
77 'type' => MENU_CALLBACK,
78 );
79
80 $items['admin/build/views/delete/%views_ui_cache'] = $callback + array(
81 'title' => t('Delete view'),
82 'page callback' => 'drupal_get_form',
83 'page arguments' => array('views_ui_delete_confirm', 4),
84 );
85 $items['admin/build/views/export/%views_ui_cache'] = $callback + array(
86 'page callback' => 'drupal_get_form',
87 'page arguments' => array('views_ui_export_page', 4),
88 );
89 $items['admin/build/views/clone/%views_ui_cache'] = $callback + array(
90 'page callback' => 'views_ui_clone_page',
91 'page arguments' => array(4),
92 );
93 $items['admin/build/views/enable/%views_ui_default'] = $callback + array(
94 'page callback' => 'views_ui_enable_page',
95 'page arguments' => array(4),
96 );
97 $items['admin/build/views/disable/%views_ui_default'] = $callback + array(
98 'page callback' => 'views_ui_disable_page',
99 'page arguments' => array(4),
100 );
101
102 // Many line items for editing a view.
103 $items['admin/build/views/edit/%views_ui_cache'] = $base + array(
104 'title' => t('Edit'),
105 'page callback' => 'views_ui_edit_page',
106 'page arguments' => array(4),
107 'type' => MENU_LOCAL_TASK
108 );
109 // lots of little edit form pieces.
110 $items['admin/build/views/%views_ui_js/details/%views_ui_cache'] = $callback + array(
111 'page callback' => 'views_ui_edit_details',
112 'page arguments' => array(3, 5),
113 );
114 $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
115 'page callback' => 'views_ui_add_display',
116 'page arguments' => array(3, 5),
117 );
118 $items['admin/build/views/%views_ui_js/remove-display/%views_ui_cache'] = $callback + array(
119 'page callback' => 'views_ui_remove_display',
120 'page arguments' => array(3, 5),
121 );
122 $items['admin/build/views/%views_ui_js/rearrange/%views_ui_cache'] = $callback + array(
123 'page callback' => 'views_ui_rearrange_type',
124 'page arguments' => array(3, 5),
125 );
126 $items['admin/build/views/%views_ui_js/add-item/%views_ui_cache'] = $callback + array(
127 'page callback' => 'views_ui_add_item',
128 'page arguments' => array(3, 5),
129 );
130 $items['admin/build/views/%views_ui_js/config-item/%views_ui_cache'] = $callback + array(
131 'page callback' => 'views_ui_config_item',
132 'page arguments' => array(3, 5),
133 );
134 // display specific parameters
135 $items['admin/build/views/%views_ui_js/display/%views_ui_cache'] = $callback + array(
136 'page callback' => 'views_ui_edit_display',
137 'page arguments' => array(3, 5),
138 );
139 // Special style plugin stuff for arguments
140 $items['admin/build/views/%views_ui_js/change-style/%views_ui_cache'] = $callback + array(
141 'page callback' => 'views_ui_change_style',
142 'page arguments' => array(3, 5),
143 );
144 $items['admin/build/views/%views_ui_js/config-style/%views_ui_cache'] = $callback + array(
145 'page callback' => 'views_ui_config_style',
146 'page arguments' => array(3, 5),
147 );
148 // Live preview
149 $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
150 'page callback' => 'views_ui_preview',
151 'page arguments' => array(3, 5),
152 );
153 return $items;
154 }
155
156 function views_ui_help($path, $arg) {
157 switch ($path) {
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>';
160 }
161 }
162
163 /*
164 * Implementation of hook_perm()
165 */
166 function views_ui_perm() {
167 return array('administer views');
168 }
169
170 function views_ui_theme() {
171 $path = drupal_get_path('module', 'views');
172 include_once "$path/includes/admin.inc";
173
174 return array(
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 'views_tabset' => array(
195 'arguments' => array('tabs' => NULL),
196 'file' => '/includes/tabs.inc',
197 ),
198 'views_tab' => array(
199 'arguments' => array('body' => NULL),
200 'file' => '/includes/tabs.inc',
201 ),
202
203 'views_ui_style_plugin_table' => array(
204 'arguments' => array('form' => NULL),
205 ),
206
207 );
208 }
209
210 /**
211 * Specialized menu callback to load a view either out of the cache or just
212 * load it.
213 */
214 function views_ui_cache_load($name) {
215 views_include('cache');
216 views_include('view');
217 $view = views_object_cache_get('view', $name);
218
219 if (empty($view)) {
220 $v = views_get_view($name);
221 if ($v) {
222 $view = drupal_clone($v);
223 }
224 }
225
226 if (empty($view)) {
227 return FALSE;
228 }
229
230 else {
231 return $view;
232 }
233 }
234
235 /**
236 * Specialized menu callback to load a view that is only a default
237 * view.
238 */
239 function views_ui_default_load($name) {
240 $view = views_get_view($name);
241 if ($view->type == t('Default')) {
242 return $view;
243 }
244
245 return FALSE;
246 }
247
248 /**
249 * Check to see if the incoming menu item is js capable or not.
250 */
251 function views_ui_js_load($js) {
252 if ($js == 'ajax') {
253 return TRUE;
254 }
255 return 0;
256 }
257
258 /**
259 * Specialized cache function to add a flag to our view, include an appropriate
260 * include, and cache more easily.
261 */
262 function views_ui_cache_set($view) {
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 }