views_panes.inc

  1. cis7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  2. cle7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  3. ecd7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  5. harmony7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  6. icor7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
  8. mooc7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc

Content type plugin to allow Views to be exposed as a display type, leaving most of the configuration on the view.

Functions

Namesort descending Description
views_content_views_panes_add_defaults Add defaults to view pane settings. This helps cover us if $allow settings changed and there are no actual settings for a particular item.
views_content_views_panes_content_type_admin_info Returns the administrative title for a type.
views_content_views_panes_content_type_admin_title Returns the administrative title for a type.
views_content_views_panes_content_type_content_type Return a single content type.
views_content_views_panes_content_type_content_types Return all content types available.
views_content_views_panes_content_type_edit_form Returns an edit form for a block.
views_content_views_panes_content_type_edit_form_submit Store form values in $conf.
views_content_views_panes_content_type_render Output function for the 'views' content type.
views_content_views_panes_ctools_content_types Implements hook_ctools_content_types()
_views_content_panes_content_type

File

sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views_panes.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Content type plugin to allow Views to be exposed as a display type,
  5. * leaving most of the configuration on the view.
  6. */
  7. /**
  8. * Implements hook_ctools_content_types()
  9. */
  10. function views_content_views_panes_ctools_content_types() {
  11. return array(
  12. 'title' => t('View panes'),
  13. 'admin settings' => 'views_content_admin_form',
  14. 'all contexts' => TRUE,
  15. );
  16. }
  17. /**
  18. * Return all content types available.
  19. */
  20. function views_content_views_panes_content_type_content_types($plugin) {
  21. $types = array();
  22. // It can be fairly intensive to calculate this, so let's cache this in the
  23. // cache_views table. The nice thing there is that if views ever change, that
  24. // table will always be cleared. Except for the occasional default view, so
  25. // we must use the Views caching functions in order to respect Views caching
  26. // settings.
  27. views_include('cache');
  28. $data = views_cache_get('views_content_panes', TRUE);
  29. if (!empty($data->data)) {
  30. $types = $data->data;
  31. }
  32. if (empty($types)) {
  33. $types = array();
  34. $views = views_get_all_views();
  35. foreach ($views as $view) {
  36. if (!empty($view->disabled)) {
  37. continue;
  38. }
  39. $view->init_display();
  40. foreach ($view->display as $id => $display) {
  41. if (empty($display->handler->panel_pane_display)) {
  42. continue;
  43. }
  44. $info = _views_content_panes_content_type($view, $display);
  45. if ($info) {
  46. $types[$view->name . '-' . $id] = $info;
  47. }
  48. }
  49. $view->destroy();
  50. }
  51. views_cache_set('views_content_panes', $types, TRUE);
  52. }
  53. return $types;
  54. }
  55. /**
  56. * Return a single content type.
  57. */
  58. function views_content_views_panes_content_type_content_type($subtype, $plugin) {
  59. list($name, $display) = explode('-', $subtype);
  60. $view = views_get_view($name);
  61. if (empty($view)) {
  62. return;
  63. }
  64. $view->set_display($display);
  65. $retval = _views_content_panes_content_type($view, $view->display[$display]);
  66. $view->destroy();
  67. return $retval;
  68. }
  69. function _views_content_panes_content_type($view, $display) {
  70. // Ensure the handler is the right type, as Views will fall back to
  71. // the default display if something is broken:
  72. if (!is_a($display->handler, 'views_content_plugin_display_panel_pane')) {
  73. return;
  74. }
  75. $title = views_content_get_display_title($view, $display->id);
  76. $description = $display->handler->get_option('pane_description');
  77. if (!$description) {
  78. $description = $view->description;
  79. }
  80. $category = $display->handler->get_option('pane_category');
  81. if (!$category['name']) {
  82. $category['name'] = t('View panes');
  83. }
  84. $icon = 'icon_views_page.png';
  85. $contexts = array();
  86. $arguments = $display->handler->get_argument_input();
  87. ctools_include('views');
  88. foreach ($arguments as $argument) {
  89. $contexts[] = ctools_views_get_argument_context($argument);
  90. }
  91. $allow = $display->handler->get_option('allow');
  92. return array(
  93. 'title' => $title,
  94. 'icon' => $icon,
  95. 'description' => filter_xss_admin($description),
  96. 'required context' => $contexts,
  97. 'category' => array($category['name'], $category['weight']),
  98. 'no title override' => empty($allow['title_override']),
  99. );
  100. }
  101. /**
  102. * Output function for the 'views' content type.
  103. *
  104. * Outputs a view based on the module and delta supplied in the configuration.
  105. */
  106. function views_content_views_panes_content_type_render($subtype, $conf, $panel_args, $contexts) {
  107. if (!is_array($contexts)) {
  108. $contexts = array($contexts);
  109. }
  110. list($name, $display) = explode('-', $subtype);
  111. $view = views_get_view($name);
  112. if (empty($view)) {
  113. return;
  114. }
  115. $view->set_display($display);
  116. views_content_views_panes_add_defaults($conf, $view);
  117. if (!$view->display_handler->access($GLOBALS['user']) || empty($view->display_handler->panel_pane_display)) {
  118. return;
  119. }
  120. $view->display_handler->set_pane_conf($conf);
  121. $args = array();
  122. $arguments = $view->display_handler->get_option('arguments');
  123. $context_keys = isset($conf['context']) ? $conf['context'] : array();
  124. foreach ($view->display_handler->get_argument_input() as $id => $argument) {
  125. switch ($argument['type']) {
  126. case 'context':
  127. $key = array_shift($context_keys);
  128. if (isset($contexts[$key])) {
  129. if (strpos($argument['context'], '.')) {
  130. list($context, $converter) = explode('.', $argument['context'], 2);
  131. $args[] = ctools_context_convert_context($contexts[$key], $converter, array('sanitize' => FALSE));
  132. }
  133. else {
  134. $args[] = $contexts[$key]->argument;
  135. }
  136. }
  137. else {
  138. $args[] = isset($arguments[$id]['exception']['value']) ? $arguments[$id]['exception']['value'] : 'all';
  139. }
  140. break;
  141. case 'fixed':
  142. $args[] = $argument['fixed'];
  143. break;
  144. case 'panel':
  145. $args[] = isset($panel_args[$argument['panel']]) ? $panel_args[$argument['panel']] : NULL;
  146. break;
  147. case 'user':
  148. $args[] = (isset($conf['arguments'][$id]) && $conf['arguments'][$id] !== '') ? ctools_context_keyword_substitute($conf['arguments'][$id], array(), $contexts) : NULL;
  149. break;
  150. case 'wildcard':
  151. // Put in the wildcard.
  152. $args[] = isset($arguments[$id]['wildcard']) ? $arguments[$id]['wildcard'] : '*';
  153. break;
  154. case 'none':
  155. default:
  156. // Put in NULL.
  157. // views.module knows what to do with NULL (or missing) arguments
  158. $args[] = NULL;
  159. break;
  160. }
  161. }
  162. // remove any trailing NULL arguments as these are non-args:
  163. while (count($args) && end($args) === NULL) {
  164. array_pop($args);
  165. }
  166. $view->set_arguments($args);
  167. $allow = $view->display_handler->get_option('allow');
  168. if (!empty($conf['path'])) {
  169. $conf['path'] = ctools_context_keyword_substitute($conf['path'], array(), $contexts);
  170. }
  171. if ($allow['path_override'] && !empty($conf['path'])) {
  172. $view->override_path = $conf['path'];
  173. }
  174. else if ($path = $view->display_handler->get_option('inherit_panels_path')) {
  175. $view->override_path = $_GET['q'];
  176. }
  177. $block = new stdClass();
  178. $block->module = 'views';
  179. $block->delta = $view->name . '-' . $display;
  180. if (($allow['link_to_view'] && !empty($conf['link_to_view'])) ||
  181. (!$allow['link_to_view'] && $view->display_handler->get_option('link_to_view'))) {
  182. $block->title_link = $view->get_url();
  183. }
  184. // more link
  185. if ($allow['more_link']) {
  186. if (empty($conf['more_link'])) {
  187. $view->display_handler->set_option('use_more', FALSE);
  188. }
  189. else {
  190. $view->display_handler->set_option('use_more', TRUE);
  191. // make sure the view runs the count query so we know whether or not the
  192. // more link applies.
  193. $view->get_total_rows = TRUE;
  194. }
  195. }
  196. if ($allow['items_per_page'] && isset($conf['items_per_page'])) {
  197. $view->set_items_per_page($conf['items_per_page']);
  198. }
  199. if ($allow['offset']) {
  200. $view->set_offset($conf['offset']);
  201. }
  202. if ($allow['use_pager']) {
  203. // Only set use_pager if they differ, this way we can avoid overwriting the
  204. // pager type that Views uses.
  205. $pager = $view->display_handler->get_option('pager');
  206. if ($conf['use_pager'] && ($pager['type'] == 'none' || $pager['type'] == 'some')) {
  207. $pager['type'] = 'full';
  208. }
  209. elseif (!$conf['use_pager'] && $pager['type'] != 'none' && $pager['type'] != 'some') {
  210. $pager['type'] = $view->get_items_per_page() || !empty($pager['options']['items_per_page']) ? 'some' : 'none';
  211. }
  212. if ($conf['use_pager']) {
  213. if (!isset($pager['options']['id']) || (isset($conf['pager_id']) && $pager['options']['id'] != $conf['pager_id'])) {
  214. $pager['options']['id'] = (int) $conf['pager_id'];
  215. }
  216. }
  217. $view->display_handler->set_option('pager', $pager);
  218. }
  219. if ($allow['fields_override']) {
  220. if ($conf['fields_override']) {
  221. $fields = $view->get_items('field');
  222. foreach ($fields as $field => $display) {
  223. $fields[$field]['exclude'] = empty($conf['fields_override'][$field]);
  224. }
  225. $view->display_handler->set_option('fields', $fields);
  226. }
  227. }
  228. if ($allow['exposed_form'] && !empty($conf['exposed'])) {
  229. $view->set_exposed_input($conf['exposed']);
  230. }
  231. $stored_feeds = drupal_add_feed();
  232. $block->content = $view->preview();
  233. if (empty($view->result) && !$view->display_handler->get_option('empty') && empty($view->style_plugin->definition['even empty'])) {
  234. return;
  235. }
  236. $block->title = $view->get_title();
  237. if (empty($view->total_rows) || $view->total_rows <= $view->get_items_per_page()) {
  238. unset($block->more);
  239. }
  240. if ((!empty($allow['feed_icons']) && !empty($conf['feed_icons'])) ||
  241. (empty($allow['feed_icons']) && $view->display_handler->get_option('feed_icons'))) {
  242. $new_feeds = drupal_add_feed();
  243. if ($diff = array_diff(array_keys($new_feeds), array_keys($stored_feeds))) {
  244. foreach ($diff as $url) {
  245. $block->feeds[$url] = $new_feeds[$url];
  246. }
  247. }
  248. }
  249. return $block;
  250. }
  251. /**
  252. * Add defaults to view pane settings.
  253. * This helps cover us if $allow settings changed and there are no actual
  254. * settings for a particular item.
  255. */
  256. function views_content_views_panes_add_defaults(&$conf, $view) {
  257. $pager = $view->display_handler->get_option('pager');
  258. $conf += array(
  259. 'link_to_view' => $view->display_handler->get_option('link_to_view'),
  260. 'more_link' => $view->display_handler->get_option('more_link'),
  261. 'feed_icons' => FALSE,
  262. 'use_pager' => $pager['type'] != 'none' && $pager['type'] != 'some',
  263. 'pager_id' => isset($pager['options']['id']) ? $pager['options']['id'] : 0,
  264. 'items_per_page' => !empty($pager['options']['items_per_page']) ? $pager['options']['items_per_page'] : 10,
  265. 'offset' => !empty($pager['options']['offset']) ? $pager['options']['offset'] : 0,
  266. 'path_override' => FALSE,
  267. 'path' => $view->get_path(),
  268. 'fields_override' => $view->display_handler->get_option('fields_override'),
  269. );
  270. }
  271. /**
  272. * Returns an edit form for a block.
  273. */
  274. function views_content_views_panes_content_type_edit_form($form, &$form_state) {
  275. $conf = $form_state['conf'];
  276. $contexts = $form_state['contexts'];
  277. // This allows older content to continue to work, where we used to embed
  278. // the display directly.
  279. list($name, $display_id) = explode('-', $form_state['subtype_name']);
  280. $view = views_get_view($name);
  281. if (empty($view)) {
  282. $form['markup'] = array('#markup' => t('Broken/missing/deleted view.'));
  283. return $form;
  284. }
  285. $view->set_display($display_id);
  286. // If it couldn't set the display and we got the default display instead,
  287. // fail.
  288. if ($view->current_display == 'default') {
  289. $form['markup'] = array('#markup' => t('Broken/missing/deleted view display.'));
  290. return $form;
  291. }
  292. $allow = $view->display_handler->get_option('allow');
  293. // Provide defaults for everything in order to prevent warnings.
  294. views_content_views_panes_add_defaults($conf, $view);
  295. $form['arguments']['#tree'] = TRUE;
  296. foreach ($view->display_handler->get_argument_input() as $id => $argument) {
  297. if ($argument['type'] == 'user') {
  298. $form['arguments'][$id] = array(
  299. '#type' => 'textfield',
  300. '#default_value' => isset($conf['arguments'][$id]) ? $conf['arguments'][$id] : '',
  301. '#description' => t('You may use keywords for substitutions.'),
  302. '#title' => check_plain($argument['label']),
  303. );
  304. }
  305. }
  306. if ($allow['link_to_view'] ) {
  307. $form['link_to_view'] = array(
  308. '#type' => 'checkbox',
  309. '#default_value' => isset($conf['link_to_view']) ? $conf['link_to_view'] : $view->display_handler->get_option('link_to_view'),
  310. '#title' => t('Link title to page'),
  311. );
  312. }
  313. if ($allow['more_link']) {
  314. $form['more_link'] = array(
  315. '#type' => 'checkbox',
  316. '#default_value' => isset($conf['more_link']) ? $conf['more_link'] : $view->display_handler->get_option('use_more'),
  317. '#description' => t('The text of this link will be "@more". This setting can only be modified on the View configuration.', array('@more' => $view->display_handler->use_more_text())),
  318. '#title' => t('Provide a "more" link.'),
  319. );
  320. }
  321. if (!empty($allow['feed_icons'])) {
  322. $form['feed_icons'] = array(
  323. '#type' => 'checkbox',
  324. '#default_value' => !empty($conf['feed_icons']),
  325. '#title' => t('Display feed icons'),
  326. );
  327. }
  328. $view->init_style();
  329. if ($allow['fields_override'] && $view->style_plugin->uses_fields()) {
  330. $form['fields_override'] = array(
  331. '#type' => 'fieldset',
  332. '#title' => 'Fields to display',
  333. '#collapsible' => TRUE,
  334. '#tree' => TRUE,
  335. );
  336. foreach ($view->display_handler->get_handlers('field') as $field => $handler) {
  337. $title = $handler->ui_name();
  338. if ($handler->options['label']) {
  339. $title .= ' (' . check_plain($handler->options['label']) . ')';
  340. }
  341. $form['fields_override'][$field] = array(
  342. '#type' => 'checkbox',
  343. '#title' => $title,
  344. '#default_value' => isset($conf['fields_override'][$field]) ? $conf['fields_override'][$field] : TRUE,
  345. );
  346. }
  347. }
  348. ctools_include('dependent');
  349. if ($allow['use_pager']) {
  350. $form['use_pager'] = array(
  351. '#type' => 'checkbox',
  352. '#title' => t('Use pager'),
  353. '#default_value' => $conf['use_pager'],
  354. '#id' => 'use-pager-checkbox',
  355. '#prefix' => '<div class="container-inline">',
  356. );
  357. $form['pager_id'] = array(
  358. '#type' => 'textfield',
  359. '#default_value' => $conf['pager_id'],
  360. '#title' => t('Pager ID'),
  361. '#size' => 4,
  362. '#id' => 'use-pager-textfield',
  363. '#dependency' => array('use-pager-checkbox' => array(1)),
  364. '#suffix' => '</div>',
  365. );
  366. }
  367. if ($allow['items_per_page']) {
  368. $form['items_per_page'] = array(
  369. '#type' => 'textfield',
  370. '#default_value' => $conf['items_per_page'],
  371. '#title' => t('Num items'),
  372. '#size' => 4,
  373. '#description' => t('Select the number of items to display, or 0 to display all results.'),
  374. );
  375. }
  376. if ($allow['offset']) {
  377. $form['offset'] = array(
  378. '#type' => 'textfield',
  379. '#default_value' => $conf['offset'],
  380. '#title' => t('Offset'),
  381. '#size' => 4,
  382. '#description' => t('Enter the number of items to skip; enter 0 to skip no items.'),
  383. );
  384. }
  385. if ($allow['path_override']) {
  386. $form['path'] = array(
  387. '#type' => 'textfield',
  388. '#default_value' => isset($conf['path']) ? $conf['path'] : $view->get_path(),
  389. '#title' => t('Override path'),
  390. '#size' => 30,
  391. '#description' => t('If this is set, override the View URL path; this can sometimes be useful to set to the panel URL.'),
  392. );
  393. if (!empty($contexts)) {
  394. $form['path']['#description'] .= ' ' . t('You may use substitutions in this path.');
  395. $form['contexts'] = array(
  396. '#type' => 'fieldset',
  397. '#title' => t('Substitutions'),
  398. '#collapsible' => TRUE,
  399. '#collapsed' => TRUE,
  400. );
  401. $rows = array();
  402. foreach ($contexts as $context) {
  403. foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
  404. $rows[] = array(
  405. check_plain($keyword),
  406. t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
  407. );
  408. }
  409. }
  410. $header = array(t('Keyword'), t('Value'));
  411. $form['contexts']['context'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $rows)));
  412. }
  413. }
  414. if (empty($conf['exposed'])) {
  415. $conf['exposed'] = array();
  416. }
  417. if ($allow['exposed_form']) {
  418. // If the exposed form is part of pane configuration, get the exposed
  419. // form re-tool it for our use.
  420. $exposed_form_state = array(
  421. 'view' => &$view,
  422. 'display' => &$view->display[$display_id],
  423. );
  424. $view->set_exposed_input($conf['exposed']);
  425. if (version_compare(views_api_version(), '3', '>=')) {
  426. $exposed_form_state['exposed_form_plugin'] = $view->display_handler->get_plugin('exposed_form');
  427. }
  428. $view->init_handlers();
  429. $exposed_form = array();
  430. $exposed_form = views_exposed_form($exposed_form, $exposed_form_state);
  431. $form['exposed'] = array(
  432. '#tree' => TRUE,
  433. );
  434. foreach ($exposed_form['#info'] as $id => $info) {
  435. $form['exposed'][$id] = array(
  436. '#type' => 'item',
  437. '#id' => 'views-exposed-pane',
  438. );
  439. if (!empty($info['label'])) {
  440. $form['exposed'][$id]['#title'] = $info['label'];
  441. }
  442. if (!empty($info['operator']) && !empty($exposed_form[$info['operator']])) {
  443. $form['exposed'][$id][$info['operator']] = $exposed_form[$info['operator']];
  444. $form['exposed'][$id][$info['operator']]['#parents'] = array('exposed', $info['operator']);
  445. $form['exposed'][$id][$info['operator']]['#default_value'] = isset($conf['exposed'][$info['operator']]) ? $conf['exposed'][$info['operator']] : '';
  446. }
  447. $form['exposed'][$id][$info['value']] = $exposed_form[$info['value']];
  448. $form['exposed'][$id][$info['value']]['#parents'] = array('exposed', $info['value']);
  449. $form['exposed'][$id][$info['value']]['#default_value'] = isset($conf['exposed'][$info['value']]) ? $conf['exposed'][$info['value']] : '';
  450. }
  451. }
  452. // The exposed sort stuff doesn't fall into $exposed_form['#info'] so we
  453. // have to handle it separately.
  454. if (isset($exposed_form['sort_by'])) {
  455. $form['exposed']['sort_by'] = $exposed_form['sort_by'];
  456. }
  457. if (isset($exposed_form['sort_order'])) {
  458. $form['exposed']['sort_order'] = $exposed_form['sort_order'];
  459. }
  460. // Add the view object to the form to allow additional customization
  461. $form_state['view'] = $view;
  462. return $form;
  463. }
  464. /**
  465. * Store form values in $conf.
  466. */
  467. function views_content_views_panes_content_type_edit_form_submit(&$form, &$form_state) {
  468. // Copy everything from our defaults.
  469. $keys = array('link_to_view', 'more_link', 'feed_icons', 'use_pager',
  470. 'pager_id', 'items_per_page', 'offset', 'path_override', 'path', 'arguments', 'fields_override', 'exposed');
  471. foreach ($keys as $key) {
  472. if (isset($form_state['values'][$key])) {
  473. $form_state['conf'][$key] = $form_state['values'][$key];
  474. }
  475. }
  476. }
  477. /**
  478. * Returns the administrative title for a type.
  479. */
  480. function views_content_views_panes_content_type_admin_title($subtype, $conf, $contexts) {
  481. list($name, $display) = explode('-', $subtype);
  482. $view = views_get_view($name);
  483. if (empty($view) || empty($view->display[$display])) {
  484. return t('Deleted/missing view @view', array('@view' => $name));
  485. }
  486. $view->set_display($display);
  487. views_content_views_panes_add_defaults($conf, $view);
  488. $title = views_content_get_display_title($view, $display);
  489. return check_plain($title);
  490. }
  491. /**
  492. * Returns the administrative title for a type.
  493. */
  494. function views_content_views_panes_content_type_admin_info($subtype, $conf, $contexts) {
  495. $info = array();
  496. list($view_name, $display_name) = explode('-', $subtype);
  497. $view = views_get_view($view_name);
  498. if (empty($view) || empty($view->display[$display_name])) {
  499. return;
  500. }
  501. $view->set_display($display_name);
  502. views_content_views_panes_add_defaults($conf, $view);
  503. // Add arguments first
  504. if (!empty($conf['arguments'])) {
  505. $keys = array_keys($conf['arguments']);
  506. $values = array_values($conf['arguments']);
  507. $argument_input = $view->display_handler->get_option('argument_input');
  508. foreach ($conf['arguments'] as $key => $value) {
  509. if(!empty($value)){
  510. $label = $argument_input[$key]['label'];
  511. $info[] = $label . ': ' . $value;
  512. }
  513. }
  514. }
  515. $block = new stdClass;
  516. if ($info) {
  517. $block->title = array_shift($info);
  518. $info[] = $view->display_handler->get_option('pane_description');
  519. $block->content = theme('item_list', array('items' => $info));
  520. }
  521. else {
  522. $block->title = $view->display_handler->get_option('pane_description');
  523. $block->content = '';
  524. }
  525. return $block;
  526. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.