views.inc

  1. cis7 sites/all/modules/ulmus/ctools/includes/views.inc
  2. cis7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  3. cis7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  4. cle7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  5. cle7 sites/all/modules/ulmus/ctools/includes/views.inc
  6. cle7 sites/all/themes/local_contrib/bootstrap/includes/modules/views.inc
  7. cle7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  8. ecd7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  9. ecd7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  10. ecd7 sites/all/modules/ulmus/ctools/includes/views.inc
  11. elmsmedia7 sites/all/modules/ulmus/ctools/includes/views.inc
  12. elmsmedia7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  13. elmsmedia7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  14. harmony7 sites/all/modules/ulmus/ctools/includes/views.inc
  15. harmony7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  16. harmony7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  17. icor7 sites/all/modules/local_contrib/entityreference_dynamicselect_widget/entityreference/plugins/selection/views.inc
  18. icor7 sites/all/modules/ulmus/ctools/includes/views.inc
  19. icor7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  20. icor7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  21. meedjum_blog7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  22. meedjum_blog7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  23. meedjum_blog7 sites/all/modules/ulmus/ctools/includes/views.inc
  24. mooc7 sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
  25. mooc7 sites/all/modules/ulmus/entityreference/plugins/selection/views.inc
  26. mooc7 sites/all/modules/ulmus/ctools/includes/views.inc

Content type plugin to expose all views as content.

Functions

Namesort descending Description
views_content_views_content_type_admin_info Returns the administrative title for a type.
views_content_views_content_type_admin_title Returns the administrative title for a type.
views_content_views_content_type_content_type Return a single content type.
views_content_views_content_type_content_types Return all content types available.
views_content_views_content_type_edit_form Returns an edit form for a block.
views_content_views_content_type_edit_form_submit Store form values in $conf.
views_content_views_content_type_render Output function for the 'views' content type.
views_content_views_select_display Returns an edit form for a block.
views_content_views_select_display_submit Submit the basic view edit form.
_views_content_views_content_type Create the content type info array to give back to ctools for a given display.
_views_content_views_update_conf Update the $conf to deal with updates from Drupal 5.

File

sites/all/modules/ulmus/ctools/views_content/plugins/content_types/views.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Content type plugin to expose all views as content.
  5. */
  6. if (variable_get('ctools_content_all_views', TRUE)) {
  7. $plugin = array(
  8. 'title' => t('All views'),
  9. 'defaults' => array(
  10. 'override_pager_settings' => FALSE,
  11. 'use_pager' => FALSE,
  12. 'nodes_per_page' => 10,
  13. 'pager_id' => 0,
  14. 'offset' => 0,
  15. 'more_link' => FALSE,
  16. 'feed_icons' => FALSE,
  17. 'panel_args' => FALSE,
  18. 'link_to_view' => FALSE,
  19. 'args' => '',
  20. 'url' => '',
  21. ),
  22. 'add form' => array(
  23. 'views_content_views_select_display' => t('Select display'),
  24. 'views_content_views_content_type_edit_form' => array(
  25. 'default' => TRUE, // put wrapper here, not on the previous form.
  26. 'title' => t('Configure view'),
  27. ),
  28. ),
  29. 'all contexts' => TRUE,
  30. );
  31. }
  32. /**
  33. * Return all content types available.
  34. */
  35. function views_content_views_content_type_content_types($plugin) {
  36. $types = array();
  37. // It can be fairly intensive to calculate this, so let's cache this in the
  38. // cache_views table. The nice thing there is that if views ever change, that
  39. // table will always be cleared. Except for the occasional default view, so
  40. // we must use the Views caching functions in order to respect Views caching
  41. // settings.
  42. views_include('cache');
  43. $data = views_cache_get('views_content_all', TRUE);
  44. if (!empty($data->data)) {
  45. $types = $data->data;
  46. }
  47. if (empty($types)) {
  48. $views = views_get_all_views();
  49. foreach ($views as $view) {
  50. if (empty($view->disabled)) {
  51. $types[$view->name] = _views_content_views_content_type($view);
  52. }
  53. }
  54. views_cache_set('views_content_all', $types, TRUE);
  55. }
  56. return $types;
  57. }
  58. /**
  59. * Return a single content type.
  60. */
  61. function views_content_views_content_type_content_type($subtype, $plugin) {
  62. $view = views_get_view($name);
  63. if (empty($view)) {
  64. return;
  65. }
  66. return _views_content_views_content_type($view);
  67. }
  68. /**
  69. * Create the content type info array to give back to ctools for a given display.
  70. */
  71. function _views_content_views_content_type($view) {
  72. $title = $view->get_human_name();
  73. $icon = 'icon_views_page_legacy.png';
  74. return array(
  75. 'view' => $view->name,
  76. 'title' => $title,
  77. 'icon' => $icon,
  78. 'description' => filter_xss_admin($view->description),
  79. 'category' => t('Views'),
  80. );
  81. }
  82. /**
  83. * Output function for the 'views' content type.
  84. *
  85. * Outputs a view based on the module and delta supplied in the configuration.
  86. */
  87. function views_content_views_content_type_render($subtype, $conf, $panel_args, $contexts) {
  88. if (!is_array($contexts)) {
  89. $contexts = array($contexts);
  90. }
  91. $view = _views_content_views_update_conf($conf, $subtype);
  92. if (empty($view) || !is_object($view) || empty($view->display_handler)) {
  93. return;
  94. }
  95. if (!$view->display_handler->access($GLOBALS['user'])) {
  96. return;
  97. }
  98. $arguments = explode('/', $_GET['q']);
  99. $args = $conf['args'];
  100. foreach ($arguments as $id => $arg) {
  101. $args = str_replace("%$id", $arg, $args);
  102. }
  103. foreach ($panel_args as $id => $arg) {
  104. if (is_string($arg)) {
  105. $args = str_replace("@$id", $arg, $args);
  106. }
  107. }
  108. $args = preg_replace(',/?(%\d|@\d),', '', $args);
  109. $args = $args ? explode('/', $args) : array();
  110. if ($conf['panel_args'] && is_array($panel_args)) {
  111. $args = array_merge($panel_args, $args);
  112. }
  113. if (isset($conf['context']) && is_array($conf['context'])) {
  114. foreach ($conf['context'] as $count => $context_info) {
  115. if (!strpos($context_info, '.')) {
  116. // old skool: support pre-converter contexts as well.
  117. $cid = $context_info;
  118. $converter = '';
  119. }
  120. else {
  121. list($cid, $converter) = explode('.', $context_info, 2);
  122. }
  123. if (!empty($contexts[$cid])) {
  124. $arg = ctools_context_convert_context($contexts[$cid], $converter, array('sanitize' => FALSE));
  125. }
  126. else {
  127. // Make sure we put an argument in even if it was not there.
  128. $arg = NULL;
  129. }
  130. array_splice($args, $count, 0, array($arg));
  131. }
  132. }
  133. $view->set_arguments($args);
  134. if ($conf['url']) {
  135. $view->override_path = $conf['url'];
  136. }
  137. $block = new stdClass();
  138. $block->module = 'views';
  139. $block->delta = $view->name . '-' . $view->current_display;
  140. if (!empty($conf['link_to_view'])) {
  141. $block->title_link = $view->get_url();
  142. }
  143. if (!empty($conf['more_link'])) {
  144. $block->more = array('href' => $view->get_url());
  145. $view->display_handler->set_option('use_more', FALSE);
  146. }
  147. // Only set use_pager if they differ, this way we can avoid overwriting the
  148. // pager type that Views uses.
  149. if ($conf['override_pager_settings']) {
  150. if (method_exists($view, 'init_pager')) {
  151. // Views 3 version
  152. $view->set_items_per_page($conf['nodes_per_page']);
  153. $view->set_offset($conf['offset']);
  154. $pager = $view->display_handler->get_option('pager');
  155. if ($conf['use_pager'] && ($pager['type'] == 'none' || $pager['type'] == 'some')) {
  156. $pager['type'] = 'full';
  157. }
  158. elseif (!$conf['use_pager'] && $pager['type'] != 'none' && $pager['type'] != 'some') {
  159. $pager['type'] = $view->get_items_per_page() ? 'some' : 'none';
  160. }
  161. if ($conf['use_pager']) {
  162. if (!isset($pager['options']['id']) || $pager['options']['id'] != $conf['pager_id']) {
  163. $pager['options']['id'] = $conf['pager_id'];
  164. }
  165. }
  166. $view->display_handler->set_option('pager', $pager);
  167. }
  168. else {
  169. if (!$view->display_handler->get_option('use_pager') || empty($conf['use_pager'])) {
  170. $view->display_handler->set_option('use_pager', $conf['use_pager']);
  171. }
  172. $view->display_handler->set_option('pager_element', $conf['pager_id']);
  173. $view->display_handler->set_option('items_per_page', $conf['nodes_per_page']);
  174. $view->display_handler->set_option('offset', $conf['offset']);
  175. }
  176. }
  177. $stored_feeds = drupal_add_feed();
  178. $block->content = $view->preview();
  179. $block->title = $view->get_title();
  180. if (empty($view->result) && !$view->display_handler->get_option('empty') && empty($view->style_plugin->definition['even empty'])) {
  181. return;
  182. }
  183. if (!empty($conf['feed_icons'])) {
  184. $new_feeds = drupal_add_feed();
  185. if ($diff = array_diff(array_keys($new_feeds), array_keys($stored_feeds))) {
  186. foreach ($diff as $url) {
  187. $block->feeds[$url] = $new_feeds[$url];
  188. }
  189. }
  190. }
  191. $view->destroy();
  192. return $block;
  193. }
  194. /**
  195. * Returns an edit form for a block.
  196. */
  197. function views_content_views_select_display($form, &$form_state) {
  198. $view = views_get_view($form_state['subtype_name']);
  199. if (empty($view)) {
  200. return;
  201. }
  202. $displays = array();
  203. foreach ($view->display as $id => $display) {
  204. // Content pane views should never be used this way.
  205. if ($display->display_plugin != 'panel_pane') {
  206. $displays[$id] = views_content_get_display_label($view, $id);
  207. }
  208. }
  209. $form['display'] = array(
  210. '#type' => 'select',
  211. '#title' => t('Display'),
  212. '#options' => $displays,
  213. '#description' => t('Choose which display of this view you wish to use.')
  214. );
  215. return $form;
  216. }
  217. /**
  218. * Submit the basic view edit form.
  219. *
  220. * This just dumps everything into the $conf array.
  221. */
  222. function views_content_views_select_display_submit(&$form, &$form_state) {
  223. $form_state['conf']['display'] = $form_state['values']['display'];
  224. }
  225. /**
  226. * Returns an edit form for a block.
  227. */
  228. function views_content_views_content_type_edit_form($form, &$form_state) {
  229. $conf = $form_state['conf'];
  230. $view = _views_content_views_update_conf($conf, $form_state['subtype_name']);
  231. if (empty($view) || !is_object($view)) {
  232. $form['markup'] = array('#value' => t('Broken/missing/deleted view.'));
  233. return;
  234. }
  235. $form_state['title'] = t('Configure view @view (@display)', array('@view' => $view->get_human_name(), '@display' => views_content_get_display_label($view, $view->current_display)));
  236. // @todo
  237. // If using the older format, just a context is listed. We should go through
  238. // and check for that and forcibly set them to the right converter so that
  239. // it doesn't get changed to some whacky default. Oooor just let it get changed
  240. // to 'no context', I suppose.
  241. $required = array();
  242. if (isset($view->display_handler) && $arguments = $view->display_handler->get_handlers('argument')) {
  243. foreach ($arguments as $arg) {
  244. $required[] = new ctools_context_optional($arg->ui_name(), 'any');
  245. }
  246. }
  247. if ($required) {
  248. $form['context'] = ctools_context_converter_selector($form_state['contexts'], $required, isset($conf['context']) ? $conf['context'] : array());
  249. }
  250. $form['link_to_view'] = array(
  251. '#type' => 'checkbox',
  252. '#default_value' => $conf['link_to_view'],
  253. '#title' => t('Link title to view'),
  254. );
  255. $form['more_link'] = array(
  256. '#type' => 'checkbox',
  257. '#default_value' => $conf['more_link'],
  258. '#title' => t('Provide a "more" link that links to the view'),
  259. '#description' => t('This is independent of any more link that may be provided by the view itself; if you see two more links, turn this one off. Views will only provide a more link if using the "block" type, however, so if using embed, use this one.'),
  260. );
  261. $form['feed_icons'] = array(
  262. '#type' => 'checkbox',
  263. '#default_value' => $conf['feed_icons'],
  264. '#title' => t('Display feed icons'),
  265. );
  266. $form['pager_settings'] = array(
  267. '#type' => 'fieldset',
  268. '#collapsible' => FALSE,
  269. '#title' => t('Custom pager settings'),
  270. );
  271. $form['pager_settings']['override_pager_settings'] = array(
  272. '#type' => 'checkbox',
  273. '#title' => t('Use different pager settings from view settings'),
  274. '#default_value' => $conf['override_pager_settings'],
  275. '#id' => 'override-pager-checkbox',
  276. );
  277. if ($view->display_handler->get_option('use_ajax')) {
  278. $form['pager_settings']['warning'] = array(
  279. '#value' => '<div>' . t('<strong>Warning: </strong> This view has AJAX enabled. Overriding the pager settings will work initially, but when the view is updated via AJAX, the original settings will be used. You should not override pager settings on Views with the AJAX setting enabled.') . '</div>',
  280. );
  281. }
  282. $form['pager_settings']['use_pager'] = array(
  283. '#prefix' => '<div class="container-inline">',
  284. '#type' => 'checkbox',
  285. '#title' => t('Use pager'),
  286. '#default_value' => $conf['use_pager'],
  287. '#id' => 'use-pager-checkbox',
  288. '#dependency' => array('override-pager-checkbox' => array(1)),
  289. );
  290. $form['pager_settings']['pager_id'] = array(
  291. '#type' => 'textfield',
  292. '#default_value' => $conf['pager_id'],
  293. '#title' => t('Pager ID'),
  294. '#size' => 4,
  295. '#id' => 'use-pager-textfield',
  296. '#dependency' => array('override-pager-checkbox' => array(1), 'use-pager-checkbox' => array(1)),
  297. '#dependency_count' => 2,
  298. '#suffix' => '</div>',
  299. );
  300. $form['pager_settings']['nodes_per_page'] = array(
  301. '#type' => 'textfield',
  302. '#default_value' => $conf['nodes_per_page'],
  303. '#size' => 4,
  304. '#title' => t('Num posts'),
  305. '#dependency' => array('override-pager-checkbox' => array(1)),
  306. );
  307. $form['pager_settings']['offset'] = array(
  308. '#type' => 'textfield',
  309. '#default_value' => $conf['offset'],
  310. '#title' => t('Offset'),
  311. '#size' => 4,
  312. '#description' => t('The number of items to skip and not display.'),
  313. '#dependency' => array('override-pager-checkbox' => array(1)),
  314. );
  315. $form['panel_args'] = array(
  316. '#type' => 'checkbox',
  317. '#title' => t('Send arguments'),
  318. '#default_value' => $conf['panel_args'],
  319. '#description' => t('Select this to send all arguments from the panel directly to the view. If checked, the panel arguments will come after any context arguments above and precede any additional arguments passed in through the Arguments field below. Note that arguments do not include the base URL; only values after the URL or set as placeholders are considered arguments.'),
  320. );
  321. $form['args'] = array(
  322. '#type' => 'textfield',
  323. '#default_value' => $conf['args'],
  324. '#title' => t('Arguments'),
  325. '#size' => 30,
  326. '#description' => t('Additional arguments to send to the view as if they were part of the URL in the form of arg1/arg2/arg3. You may use %0, %1, ..., %N to grab arguments from the URL. Or use @0, @1, @2, ..., @N to use arguments passed into the panel. Note: use these values only as a last resort. In future versions of Panels these may go away.'),
  327. );
  328. $form['url'] = array(
  329. '#type' => 'textfield',
  330. '#default_value' => $conf['url'],
  331. '#title' => t('Override URL'),
  332. '#size' => 30,
  333. '#description' => t('If this is set, override the View URL; this can sometimes be useful to set to the panel URL'),
  334. );
  335. $view->destroy();
  336. return $form;
  337. }
  338. /**
  339. * Store form values in $conf.
  340. */
  341. function views_content_views_content_type_edit_form_submit(&$form, &$form_state) {
  342. // Copy everything from our defaults.
  343. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  344. $form_state['conf'][$key] = $form_state['values'][$key];
  345. }
  346. }
  347. /**
  348. * Returns the administrative title for a type.
  349. */
  350. function views_content_views_content_type_admin_title($subtype, $conf) {
  351. $view = _views_content_views_update_conf($conf, $subtype);
  352. if (!is_object($view)) {
  353. return t('Deleted/missing view @view', array('@view' => $view));
  354. }
  355. $title = views_content_get_display_label($view, $view->current_display);
  356. return t('View: @name', array('@name' => $view->get_human_name() . ': ' . $title));
  357. }
  358. /**
  359. * Returns the administrative title for a type.
  360. */
  361. function views_content_views_content_type_admin_info($subtype, $conf, $contexts) {
  362. $view = _views_content_views_update_conf($conf, $subtype);
  363. if (!is_object($view)) {
  364. return t('Deleted/missing view @view', array('@view' => $view));
  365. }
  366. $display = empty($conf['display']) ? $view->current_display : $conf['display'];
  367. $block = new stdClass();
  368. $block->title = t('View information');
  369. $block->content = '<ul>';
  370. $block->content .= '<li>' . t('Using display @display.', array('@display' => views_content_get_display_label($view, $display))) . '</li>';
  371. if (!empty($conf['context']) && $arguments = $view->display_handler->get_handlers('argument')) {
  372. $argument = reset($arguments);
  373. foreach ($conf['context'] as $count => $context_info) {
  374. if (!$argument) {
  375. break;
  376. }
  377. if (!strpos($context_info, '.')) {
  378. // old skool: support pre-converter contexts as well.
  379. $cid = $context_info;
  380. $converter = '';
  381. }
  382. else {
  383. list($cid, $converter) = explode('.', $context_info, 2);
  384. }
  385. if (!empty($contexts[$cid])) {
  386. $converters = ctools_context_get_converters($cid . '.', $contexts[$cid]);
  387. $converter = !empty($converters[$context_info]) ? $converters[$context_info] : t('Default');
  388. $block->content .= '<li>' . t('Argument @arg using context @context converted into @converter', array(
  389. '@arg' => $argument->ui_name(), '@context' => $contexts[$cid]->get_identifier(),
  390. '@converter' => $converter)) . '</li>';
  391. }
  392. $argument = next($arguments);
  393. }
  394. }
  395. $block->content .= '<li>' . t('@count items displayed.', array('@count' => $conf['nodes_per_page'])) . '</li>';
  396. if ($conf['use_pager']) {
  397. $block->content .= '<li>' . t('With pager.') . '</li>';
  398. }
  399. else {
  400. $block->content .= '<li>' . t('Without pager.') . '</li>';
  401. }
  402. if ($conf['offset']) {
  403. $block->content .= '<li>' . t('Skipping first @count results', array('@count' => $conf['offset'])) . '</li>';
  404. }
  405. if ($conf['more_link']) {
  406. $block->content .= '<li>' . t('With more link.') . '</li>';
  407. }
  408. if ($conf['feed_icons']) {
  409. $block->content .= '<li>' . t('With feed icon.') . '</li>';
  410. }
  411. if ($conf['panel_args']) {
  412. $block->content .= '<li>' . t('Sending arguments.') . '</li>';
  413. }
  414. if ($conf['args']) {
  415. $block->content .= '<li>' . t('Using arguments: @args', array('@args' => $conf['args'])) . '</li>';
  416. }
  417. if ($conf['url']) {
  418. $block->content .= '<li>' . t('Using url: @url', array('@url' => $conf['url'])) . '</li>';
  419. }
  420. $view->destroy();
  421. return $block;
  422. }
  423. /**
  424. * Update the $conf to deal with updates from Drupal 5.
  425. *
  426. * @param &$conf
  427. * The $conf array to modify.
  428. * @param $subtype
  429. * The subtype in use. This should just be the view name, but in older
  430. * versions it was the view name with a dash and the display ID.
  431. * If this is the case, we can use it to correct the 'display' setting
  432. * in the $conf.
  433. * @return
  434. * The $view with the initialized display. If the $view could not be
  435. * loaded, the name attempted will be loaded for use in errors.
  436. * Correct error checking on this function checks against is_object().
  437. */
  438. function _views_content_views_update_conf(&$conf, $subtype) {
  439. $plugin = ctools_get_content_type('views');
  440. // Special: Existing content types get a different default than new ones:
  441. if (!empty($conf) && !isset($conf['override_pager_settings'])) {
  442. $conf['override_pager_settings'] = TRUE;
  443. }
  444. // Make sure that our defaults are always set if there is no
  445. // previous setting. This helps updates go more smoothly.
  446. foreach ($plugin['defaults'] as $key => $value) {
  447. if (!isset($conf[$key])) {
  448. $conf[$key] = $value;
  449. }
  450. }
  451. if (strpos($subtype, '-')) {
  452. list($name, $display) = explode('-', $subtype);
  453. $view = views_get_view($name);
  454. if (!isset($conf['display'])) {
  455. $conf['display'] = $display;
  456. }
  457. }
  458. else {
  459. $name = $subtype;
  460. $view = views_get_view($subtype);
  461. $display = isset($conf['display']) ? $conf['display'] : 'default';
  462. }
  463. if (empty($view)) {
  464. return $name;
  465. }
  466. $view->set_display($display);
  467. // $view->current_display will now reflect this value.
  468. // If set NOT to override, go ahead and refresh from the view.
  469. if (empty($conf['override_pager_settings'])) {
  470. if (method_exists($view, 'init_pager')) {
  471. $pager = $view->display_handler->get_option('pager');
  472. $conf['use_pager'] = $pager['type'] != 'none' && $pager['type'] != 'some';
  473. $conf['pager_id'] = isset($pager['options']['id']) ? $pager['options']['id'] : 0;
  474. $conf['offset'] = isset($pager['options']['offset']) ? $pager['options']['offset'] : 0;
  475. $conf['nodes_per_page'] = isset($pager['options']['items_per_page']) ? $pager['options']['items_per_page'] : 0;
  476. }
  477. else {
  478. $conf['use_pager'] = $view->display_handler->get_option('use_pager');
  479. $conf['pager_id'] = $view->display_handler->get_option('element_id');
  480. $conf['nodes_per_page'] = $view->display_handler->get_option('items_per_page');
  481. $conf['offset'] = $view->display_handler->get_option('offset');
  482. }
  483. }
  484. return $view;
  485. }
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.