| 1 |
<?php
|
| 2 |
// $Id: plugins.inc,v 1.155 2009/09/21 21:26:56 merlinofchaos Exp $
|
| 3 |
/**
|
| 4 |
* @file plugins.inc
|
| 5 |
* Built in plugins for Views output handling.
|
| 6 |
*
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_views_plugins
|
| 11 |
*/
|
| 12 |
function views_views_plugins() {
|
| 13 |
$path = drupal_get_path('module', 'views') . '/js';
|
| 14 |
return array(
|
| 15 |
'module' => 'views', // This just tells our themes are elsewhere.
|
| 16 |
'display' => array(
|
| 17 |
'parent' => array(
|
| 18 |
// this isn't really a display but is necessary so the file can
|
| 19 |
// be included.
|
| 20 |
'no ui' => TRUE,
|
| 21 |
'handler' => 'views_plugin_display',
|
| 22 |
'parent' => '',
|
| 23 |
),
|
| 24 |
'default' => array(
|
| 25 |
'title' => t('Defaults'),
|
| 26 |
'help' => t('Default settings for this view.'),
|
| 27 |
'handler' => 'views_plugin_display_default',
|
| 28 |
'theme' => 'views_view',
|
| 29 |
'no ui' => TRUE,
|
| 30 |
'no remove' => TRUE,
|
| 31 |
'js' => array('misc/collapse.js', 'misc/textarea.js', 'misc/tabledrag.js', 'misc/autocomplete.js', "$path/dependent.js"),
|
| 32 |
'use ajax' => TRUE,
|
| 33 |
'use pager' => TRUE,
|
| 34 |
'use more' => TRUE,
|
| 35 |
'accept attachments' => TRUE,
|
| 36 |
'help topic' => 'display-default',
|
| 37 |
),
|
| 38 |
'page' => array(
|
| 39 |
'title' => t('Page'),
|
| 40 |
'help' => t('Display the view as a page, with a URL and menu links.'),
|
| 41 |
'handler' => 'views_plugin_display_page',
|
| 42 |
'theme' => 'views_view',
|
| 43 |
'uses hook menu' => TRUE,
|
| 44 |
'use ajax' => TRUE,
|
| 45 |
'use pager' => TRUE,
|
| 46 |
'accept attachments' => TRUE,
|
| 47 |
'admin' => t('Page'),
|
| 48 |
'help topic' => 'display-page',
|
| 49 |
),
|
| 50 |
'block' => array(
|
| 51 |
'title' => t('Block'),
|
| 52 |
'help' => t('Display the view as a block.'),
|
| 53 |
'handler' => 'views_plugin_display_block',
|
| 54 |
'theme' => 'views_view',
|
| 55 |
'uses hook block' => TRUE,
|
| 56 |
'use ajax' => TRUE,
|
| 57 |
'use pager' => TRUE,
|
| 58 |
'use more' => TRUE,
|
| 59 |
'accept attachments' => TRUE,
|
| 60 |
'admin' => t('Block'),
|
| 61 |
'help topic' => 'display-block',
|
| 62 |
),
|
| 63 |
'attachment' => array(
|
| 64 |
'title' => t('Attachment'),
|
| 65 |
'help' => t('Attachments added to other displays to achieve multiple views in the same view.'),
|
| 66 |
'handler' => 'views_plugin_display_attachment',
|
| 67 |
'theme' => 'views_view',
|
| 68 |
'use ajax' => TRUE,
|
| 69 |
'help topic' => 'display-attachment',
|
| 70 |
),
|
| 71 |
'feed' => array(
|
| 72 |
'title' => t('Feed'),
|
| 73 |
'help' => t('Display the view as a feed, such as an RSS feed.'),
|
| 74 |
'handler' => 'views_plugin_display_feed',
|
| 75 |
'parent' => 'page', // so it knows to load the page plugin .inc file
|
| 76 |
'uses hook menu' => TRUE,
|
| 77 |
'use ajax' => FALSE,
|
| 78 |
'use pager' => FALSE,
|
| 79 |
'accept attachments' => FALSE,
|
| 80 |
'admin' => t('Feed'),
|
| 81 |
'help topic' => 'display-feed',
|
| 82 |
),
|
| 83 |
),
|
| 84 |
'style' => array(
|
| 85 |
'parent' => array(
|
| 86 |
// this isn't really a display but is necessary so the file can
|
| 87 |
// be included.
|
| 88 |
'no ui' => TRUE,
|
| 89 |
'handler' => 'views_plugin_style',
|
| 90 |
'parent' => '',
|
| 91 |
),
|
| 92 |
'default' => array(
|
| 93 |
'title' => t('Unformatted'),
|
| 94 |
'help' => t('Displays rows one after another.'),
|
| 95 |
'handler' => 'views_plugin_style_default',
|
| 96 |
'theme' => 'views_view_unformatted',
|
| 97 |
'uses row plugin' => TRUE,
|
| 98 |
'uses grouping' => TRUE,
|
| 99 |
'uses options' => TRUE,
|
| 100 |
'type' => 'normal',
|
| 101 |
'help topic' => 'style-unformatted',
|
| 102 |
),
|
| 103 |
'list' => array(
|
| 104 |
'title' => t('HTML List'),
|
| 105 |
'help' => t('Displays rows as an HTML list.'),
|
| 106 |
'handler' => 'views_plugin_style_list',
|
| 107 |
'theme' => 'views_view_list',
|
| 108 |
'uses row plugin' => TRUE,
|
| 109 |
'uses options' => TRUE,
|
| 110 |
'type' => 'normal',
|
| 111 |
'help topic' => 'style-list',
|
| 112 |
),
|
| 113 |
'grid' => array(
|
| 114 |
'title' => t('Grid'),
|
| 115 |
'help' => t('Displays rows in a grid.'),
|
| 116 |
'handler' => 'views_plugin_style_grid',
|
| 117 |
'theme' => 'views_view_grid',
|
| 118 |
'uses row plugin' => TRUE,
|
| 119 |
'uses options' => TRUE,
|
| 120 |
'type' => 'normal',
|
| 121 |
'help topic' => 'style-grid',
|
| 122 |
),
|
| 123 |
'table' => array(
|
| 124 |
'title' => t('Table'),
|
| 125 |
'help' => t('Displays rows in a table.'),
|
| 126 |
'handler' => 'views_plugin_style_table',
|
| 127 |
'theme' => 'views_view_table',
|
| 128 |
'uses row plugin' => FALSE,
|
| 129 |
'uses fields' => TRUE,
|
| 130 |
'uses options' => TRUE,
|
| 131 |
'type' => 'normal',
|
| 132 |
'help topic' => 'style-table',
|
| 133 |
),
|
| 134 |
'default_summary' => array(
|
| 135 |
'title' => t('List'),
|
| 136 |
'help' => t('Displays the default summary as a list.'),
|
| 137 |
'handler' => 'views_plugin_style_summary',
|
| 138 |
'theme' => 'views_view_summary',
|
| 139 |
'type' => 'summary', // only shows up as a summary style
|
| 140 |
'uses options' => TRUE,
|
| 141 |
'help topic' => 'style-summary',
|
| 142 |
),
|
| 143 |
'unformatted_summary' => array(
|
| 144 |
'title' => t('Unformatted'),
|
| 145 |
'help' => t('Displays the summary unformatted, with option for one after another or inline.'),
|
| 146 |
'handler' => 'views_plugin_style_summary_unformatted',
|
| 147 |
'parent' => 'default_summary',
|
| 148 |
'theme' => 'views_view_summary_unformatted',
|
| 149 |
'type' => 'summary', // only shows up as a summary style
|
| 150 |
'uses options' => TRUE,
|
| 151 |
'help topic' => 'style-summary-unformatted',
|
| 152 |
),
|
| 153 |
'rss' => array(
|
| 154 |
'title' => t('RSS Feed'),
|
| 155 |
'help' => t('Generates an RSS feed from a view.'),
|
| 156 |
'handler' => 'views_plugin_style_rss',
|
| 157 |
'theme' => 'views_view_rss',
|
| 158 |
'uses row plugin' => TRUE,
|
| 159 |
'uses options' => TRUE,
|
| 160 |
'type' => 'feed',
|
| 161 |
'help topic' => 'style-rss',
|
| 162 |
),
|
| 163 |
),
|
| 164 |
'row' => array(
|
| 165 |
'parent' => array(
|
| 166 |
// this isn't really a display but is necessary so the file can
|
| 167 |
// be included.
|
| 168 |
'no ui' => TRUE,
|
| 169 |
'handler' => 'views_plugin_row',
|
| 170 |
'parent' => '',
|
| 171 |
),
|
| 172 |
'fields' => array(
|
| 173 |
'title' => t('Fields'),
|
| 174 |
'help' => t('Displays the fields with an optional template.'),
|
| 175 |
'handler' => 'views_plugin_row_fields',
|
| 176 |
'theme' => 'views_view_fields',
|
| 177 |
'uses fields' => TRUE,
|
| 178 |
'uses options' => TRUE,
|
| 179 |
'type' => 'normal',
|
| 180 |
'help topic' => 'style-row-fields',
|
| 181 |
),
|
| 182 |
),
|
| 183 |
'argument default' => array(
|
| 184 |
// This type of plugin does not conform to the standard and
|
| 185 |
// uses 'fixed' as the parent rather than having a separate parent.
|
| 186 |
'fixed' => array(
|
| 187 |
'title' => t('Fixed entry'),
|
| 188 |
'handler' => 'views_plugin_argument_default',
|
| 189 |
),
|
| 190 |
'php' => array(
|
| 191 |
'title' => t('PHP Code'),
|
| 192 |
'handler' => 'views_plugin_argument_default_php',
|
| 193 |
'parent' => 'fixed',
|
| 194 |
),
|
| 195 |
),
|
| 196 |
'argument validator' => array(
|
| 197 |
'parent' => array(
|
| 198 |
'no ui' => TRUE,
|
| 199 |
'handler' => 'views_plugin_argument_validate',
|
| 200 |
'parent' => '',
|
| 201 |
),
|
| 202 |
'php' => array(
|
| 203 |
'title' => t('PHP Code'),
|
| 204 |
'handler' => 'views_plugin_argument_validate_php',
|
| 205 |
),
|
| 206 |
'numeric' => array(
|
| 207 |
'title' => t('Numeric'),
|
| 208 |
'handler' => 'views_plugin_argument_validate_numeric',
|
| 209 |
),
|
| 210 |
),
|
| 211 |
'access' => array(
|
| 212 |
'parent' => array(
|
| 213 |
'no ui' => TRUE,
|
| 214 |
'handler' => 'views_plugin_access',
|
| 215 |
'parent' => '',
|
| 216 |
),
|
| 217 |
'none' => array(
|
| 218 |
'title' => t('None'),
|
| 219 |
'help' => t('Will be available to all users.'),
|
| 220 |
'handler' => 'views_plugin_access_none',
|
| 221 |
'help topic' => 'access-none',
|
| 222 |
),
|
| 223 |
'role' => array(
|
| 224 |
'title' => t('Role'),
|
| 225 |
'help' => t('Access will be granted to users with any of the specified roles.'),
|
| 226 |
'handler' => 'views_plugin_access_role',
|
| 227 |
'uses options' => TRUE,
|
| 228 |
'help topic' => 'access-role',
|
| 229 |
),
|
| 230 |
'perm' => array(
|
| 231 |
'title' => t('Permission'),
|
| 232 |
'help' => t('Access will be granted to users with the specified permission string.'),
|
| 233 |
'handler' => 'views_plugin_access_perm',
|
| 234 |
'uses options' => TRUE,
|
| 235 |
'help topic' => 'access-perm',
|
| 236 |
),
|
| 237 |
),
|
| 238 |
'cache' => array(
|
| 239 |
'parent' => array(
|
| 240 |
'no ui' => TRUE,
|
| 241 |
'handler' => 'views_plugin_cache',
|
| 242 |
'parent' => '',
|
| 243 |
),
|
| 244 |
'none' => array(
|
| 245 |
'title' => t('None'),
|
| 246 |
'help' => t('No caching of Views data.'),
|
| 247 |
'handler' => 'views_plugin_cache_none',
|
| 248 |
'help topic' => 'cache-none',
|
| 249 |
),
|
| 250 |
'time' => array(
|
| 251 |
'title' => t('Time-based'),
|
| 252 |
'help' => t('Simple time-based caching of data.'),
|
| 253 |
'handler' => 'views_plugin_cache_time',
|
| 254 |
'uses options' => TRUE,
|
| 255 |
'help topic' => 'cache-time',
|
| 256 |
),
|
| 257 |
),
|
| 258 |
);
|
| 259 |
}
|
| 260 |
|
| 261 |
/**
|
| 262 |
* Builds and return a list of all plugins available in the system.
|
| 263 |
*
|
| 264 |
* @return Nested array of plugins, grouped by type.
|
| 265 |
*/
|
| 266 |
function views_discover_plugins() {
|
| 267 |
$cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array(), 'cache' => array());
|
| 268 |
// Get plugins from all mdoules.
|
| 269 |
foreach (module_implements('views_plugins') as $module) {
|
| 270 |
$function = $module . '_views_plugins';
|
| 271 |
$result = $function();
|
| 272 |
if (!is_array($result)) {
|
| 273 |
continue;
|
| 274 |
}
|
| 275 |
|
| 276 |
$module_dir = isset($result['module']) ? $result['module'] : $module;
|
| 277 |
// Setup automatic path/file finding for theme registration
|
| 278 |
if ($module_dir == 'views') {
|
| 279 |
$theme_path = drupal_get_path('module', $module_dir) . '/theme';
|
| 280 |
$theme_file = 'theme.inc';
|
| 281 |
$path = drupal_get_path('module', $module_dir) . '/plugins';
|
| 282 |
}
|
| 283 |
else {
|
| 284 |
$theme_path = $path = drupal_get_path('module', $module_dir);
|
| 285 |
$theme_file = "$module.views.inc";
|
| 286 |
}
|
| 287 |
|
| 288 |
foreach ($result as $type => $info) {
|
| 289 |
if ($type == 'module') {
|
| 290 |
continue;
|
| 291 |
}
|
| 292 |
foreach ($info as $plugin => $def) {
|
| 293 |
$def['module'] = $module_dir;
|
| 294 |
if (!isset($def['theme path'])) {
|
| 295 |
$def['theme path'] = $theme_path;
|
| 296 |
}
|
| 297 |
if (!isset($def['theme file'])) {
|
| 298 |
$def['theme file'] = $theme_file;
|
| 299 |
}
|
| 300 |
if (!isset($def['path'])) {
|
| 301 |
$def['path'] = $path;
|
| 302 |
}
|
| 303 |
if (!isset($def['file'])) {
|
| 304 |
$def['file'] = $def['handler'] . '.inc';
|
| 305 |
}
|
| 306 |
if (!isset($def['parent'])) {
|
| 307 |
$def['parent'] = 'parent';
|
| 308 |
}
|
| 309 |
// merge the new data in
|
| 310 |
$cache[$type][$plugin] = $def;
|
| 311 |
}
|
| 312 |
}
|
| 313 |
}
|
| 314 |
return $cache;
|
| 315 |
}
|
| 316 |
|
| 317 |
/**
|
| 318 |
* Abstract base class to provide interface common to all plugins.
|
| 319 |
*/
|
| 320 |
class views_plugin extends views_object {
|
| 321 |
/**
|
| 322 |
* Init will be called after construct, when the plugin is attached to a
|
| 323 |
* view and a display.
|
| 324 |
*/
|
| 325 |
function init(&$view, &$display) {
|
| 326 |
$this->view = &$view;
|
| 327 |
$this->display = &$display;
|
| 328 |
}
|
| 329 |
|
| 330 |
/**
|
| 331 |
* Provide a form to edit options for this plugin.
|
| 332 |
*/
|
| 333 |
function options_form(&$form, &$form_state) { }
|
| 334 |
|
| 335 |
/**
|
| 336 |
* Validate the options form.
|
| 337 |
*/
|
| 338 |
function options_validate(&$form, &$form_state) { }
|
| 339 |
|
| 340 |
/**
|
| 341 |
* Handle any special handling on the validate form.
|
| 342 |
*/
|
| 343 |
function options_submit(&$form, &$form_state) { }
|
| 344 |
|
| 345 |
/**
|
| 346 |
* Add anything to the query that we might need to.
|
| 347 |
*/
|
| 348 |
function query() { }
|
| 349 |
|
| 350 |
/**
|
| 351 |
* Provide a full list of possible theme templates used by this style.
|
| 352 |
*/
|
| 353 |
function theme_functions() {
|
| 354 |
return views_theme_functions($this->definition['theme'], $this->view, $this->display);
|
| 355 |
}
|
| 356 |
|
| 357 |
/**
|
| 358 |
* Provide a list of additional theme functions for the theme information page
|
| 359 |
*/
|
| 360 |
function additional_theme_functions() {
|
| 361 |
$funcs = array();
|
| 362 |
if (!empty($this->definition['additional themes'])) {
|
| 363 |
foreach ($this->definition['additional themes'] as $theme => $type) {
|
| 364 |
$funcs[] = views_theme_functions($theme, $this->view, $this->display);
|
| 365 |
}
|
| 366 |
}
|
| 367 |
return $funcs;
|
| 368 |
}
|
| 369 |
|
| 370 |
/**
|
| 371 |
* Validate that the plugin is correct and can be saved.
|
| 372 |
*
|
| 373 |
* @return
|
| 374 |
* An array of error strings to tell the user what is wrong with this
|
| 375 |
* plugin.
|
| 376 |
*/
|
| 377 |
function validate() { return array(); }
|
| 378 |
}
|
| 379 |
|