| 1 |
<?php
|
| 2 |
// $Id: views_ui.module,v 1.108 2008/12/03 02:39:45 merlinofchaos Exp $
|
| 3 |
/**
|
| 4 |
* @file views_ui.module
|
| 5 |
* Provide structure for the administrative interface to Views.
|
| 6 |
*/
|
| 7 |
|
| 8 |
/*
|
| 9 |
* Implementation of hook_menu()
|
| 10 |
*/
|
| 11 |
function views_ui_menu() {
|
| 12 |
$items = array();
|
| 13 |
|
| 14 |
// Minor code reduction technique
|
| 15 |
$base = array(
|
| 16 |
'access callback' => 'user_access',
|
| 17 |
'access arguments' => array('administer views'),
|
| 18 |
'file' => 'includes/admin.inc',
|
| 19 |
);
|
| 20 |
|
| 21 |
$callback = $base + array('type' => MENU_CALLBACK);
|
| 22 |
|
| 23 |
$convert = array('file' => 'includes/convert.inc') + $base;
|
| 24 |
|
| 25 |
$items['admin/build/views'] = $base + array(
|
| 26 |
'title' => 'Views',
|
| 27 |
'page callback' => 'views_ui_list_views',
|
| 28 |
'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.',
|
| 29 |
'type' => MENU_NORMAL_ITEM
|
| 30 |
);
|
| 31 |
$items['admin/build/views/list'] = $base + array(
|
| 32 |
'title' => 'List',
|
| 33 |
'page callback' => 'views_ui_list_views',
|
| 34 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 35 |
'weight' => '-1'
|
| 36 |
);
|
| 37 |
$items['admin/build/views/add'] = $base + array(
|
| 38 |
'title' => 'Add',
|
| 39 |
'page callback' => 'views_ui_add_page',
|
| 40 |
'type' => MENU_LOCAL_TASK
|
| 41 |
);
|
| 42 |
$items['admin/build/views/import'] = $base + array(
|
| 43 |
'title' => 'Import',
|
| 44 |
'page callback' => 'drupal_get_form',
|
| 45 |
'page arguments' => array('views_ui_import_page'),
|
| 46 |
'type' => MENU_LOCAL_TASK
|
| 47 |
);
|
| 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/details/%views_ui_cache'] = $callback + array(
|
| 124 |
'page callback' => 'views_ui_edit_details',
|
| 125 |
'page arguments' => array(3, 5),
|
| 126 |
);
|
| 127 |
$items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array(
|
| 128 |
'page callback' => 'views_ui_add_display',
|
| 129 |
'page arguments' => array(3, 5),
|
| 130 |
);
|
| 131 |
// Live preview
|
| 132 |
$items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array(
|
| 133 |
'page callback' => 'views_ui_preview',
|
| 134 |
'page arguments' => array(3, 5),
|
| 135 |
);
|
| 136 |
|
| 137 |
// autocompletes for handlers and such
|
| 138 |
$items['admin/views/ajax/autocomplete/tag'] = $callback + array(
|
| 139 |
'page callback' => 'views_ui_autocomplete_tag',
|
| 140 |
);
|
| 141 |
|
| 142 |
|
| 143 |
// Generic ajax callback
|
| 144 |
// display specific parameters
|
| 145 |
$items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array(
|
| 146 |
'page callback' => 'views_ui_ajax_form',
|
| 147 |
'page arguments' => array(3, 4, 5),
|
| 148 |
);
|
| 149 |
|
| 150 |
return $items;
|
| 151 |
}
|
| 152 |
|
| 153 |
/*
|
| 154 |
* Implementation of hook_help()
|
| 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_theme()
|
| 165 |
*/
|
| 166 |
function views_ui_theme() {
|
| 167 |
$path = drupal_get_path('module', 'views');
|
| 168 |
require_once "./$path/includes/admin.inc";
|
| 169 |
|
| 170 |
return array(
|
| 171 |
// edit a view
|
| 172 |
'views_ui_edit_view' => array(
|
| 173 |
'arguments' => array('view' => NULL),
|
| 174 |
'template' => 'views-ui-edit-view',
|
| 175 |
'path' => "$path/theme",
|
| 176 |
),
|
| 177 |
'views_ui_edit_tab' => array(
|
| 178 |
'arguments' => array('view' => NULL, 'display' => NULL),
|
| 179 |
'template' => 'views-ui-edit-tab',
|
| 180 |
'path' => "$path/theme",
|
| 181 |
),
|
| 182 |
'views_ui_edit_item' => array(
|
| 183 |
'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE),
|
| 184 |
'template' => 'views-ui-edit-item',
|
| 185 |
'path' => "$path/theme",
|
| 186 |
),
|
| 187 |
'views_ui_rearrange_form' => array(
|
| 188 |
'arguments' => array('form' => NULL),
|
| 189 |
'file' => 'includes/admin.inc',
|
| 190 |
),
|
| 191 |
|
| 192 |
// list views
|
| 193 |
'views_ui_list_views' => array(
|
| 194 |
'template' => 'views-ui-list-views',
|
| 195 |
'path' => "$path/theme",
|
| 196 |
),
|
| 197 |
'views_ui_list_views_form' => array(
|
| 198 |
'file' => 'includes/admin.inc',
|
| 199 |
'arguments' => array('form' => NULL),
|
| 200 |
),
|
| 201 |
|
| 202 |
// tab themes
|
| 203 |
'views_tabset' => array(
|
| 204 |
'arguments' => array('tabs' => NULL),
|
| 205 |
'file' => 'includes/tabs.inc',
|
| 206 |
),
|
| 207 |
'views_tab' => array(
|
| 208 |
'arguments' => array('body' => NULL),
|
| 209 |
'file' => 'includes/tabs.inc',
|
| 210 |
),
|
| 211 |
|
| 212 |
// On behalf of a plugin
|
| 213 |
'views_ui_style_plugin_table' => array(
|
| 214 |
'arguments' => array('form' => NULL),
|
| 215 |
'file' => 'includes/admin.inc',
|
| 216 |
),
|
| 217 |
);
|
| 218 |
}
|
| 219 |
|
| 220 |
/**
|
| 221 |
* Specialized menu callback to load a view either out of the cache or just
|
| 222 |
* load it.
|
| 223 |
*/
|
| 224 |
function views_ui_cache_load($name) {
|
| 225 |
views_include('cache');
|
| 226 |
views_include('view');
|
| 227 |
$view = views_object_cache_get('view', $name);
|
| 228 |
|
| 229 |
if (empty($view)) {
|
| 230 |
$view = views_get_view($name);
|
| 231 |
|
| 232 |
if (!empty($view)) {
|
| 233 |
// Check to see if someone else is already editing this view.
|
| 234 |
global $user;
|
| 235 |
$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));
|
| 236 |
}
|
| 237 |
}
|
| 238 |
|
| 239 |
if (empty($view)) {
|
| 240 |
return FALSE;
|
| 241 |
}
|
| 242 |
|
| 243 |
else {
|
| 244 |
return $view;
|
| 245 |
}
|
| 246 |
}
|
| 247 |
|
| 248 |
function views_ui_check_lock($view) {
|
| 249 |
|
| 250 |
}
|
| 251 |
|
| 252 |
/**
|
| 253 |
* Specialized cache function to add a flag to our view, include an appropriate
|
| 254 |
* include, and cache more easily.
|
| 255 |
*/
|
| 256 |
function views_ui_cache_set(&$view) {
|
| 257 |
if (!empty($view->locked)) {
|
| 258 |
drupal_set_message(t('Changes cannot be made to a locked view.'), 'error');
|
| 259 |
return;
|
| 260 |
}
|
| 261 |
views_include('cache');
|
| 262 |
$view->changed = TRUE; // let any future object know that this view has changed.
|
| 263 |
|
| 264 |
// Unset handlers; we don't want to write these into the cache
|
| 265 |
unset($view->display_handler);
|
| 266 |
unset($view->current_display);
|
| 267 |
unset($view->default_display);
|
| 268 |
foreach (array_keys($view->display) as $id) {
|
| 269 |
unset($view->display[$id]->handler);
|
| 270 |
unset($view->display[$id]->default_display);
|
| 271 |
}
|
| 272 |
views_object_cache_set('view', $view->name, $view);
|
| 273 |
}
|
| 274 |
|
| 275 |
|
| 276 |
/**
|
| 277 |
* Specialized menu callback to load a view that is only a default
|
| 278 |
* view.
|
| 279 |
*/
|
| 280 |
function views_ui_default_load($name) {
|
| 281 |
$view = views_get_view($name);
|
| 282 |
if ($view->type == t('Default')) {
|
| 283 |
return $view;
|
| 284 |
}
|
| 285 |
|
| 286 |
return FALSE;
|
| 287 |
}
|
| 288 |
|
| 289 |
/**
|
| 290 |
* Check to see if the incoming menu item is js capable or not.
|
| 291 |
*/
|
| 292 |
function views_ui_js_load($js) {
|
| 293 |
if ($js == 'ajax') {
|
| 294 |
return TRUE;
|
| 295 |
}
|
| 296 |
return 0;
|
| 297 |
}
|