QuickCallbackContent.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Class for tab content of type "callback" - this is for rendering the contents
  4. * of some menu callback function as tab content.
  5. */
  6. class QuickCallbackContent extends QuickContent {
  7. public static function getType() {
  8. return 'callback';
  9. }
  10. public function __construct($item) {
  11. parent::__construct($item);
  12. if (isset($item['path'])) {
  13. $url_args = arg();
  14. $path = $item['path'];
  15. foreach ($url_args as $id => $arg) {
  16. $path = str_replace("%$id", $arg, $path);
  17. }
  18. $path = preg_replace(',/?(%\d),', '', $path);
  19. if (!empty($path)) {
  20. $this->settings['ajax_path'] = rawurlencode($path);
  21. }
  22. else {
  23. $this->settings['ajax_path'] = '';
  24. }
  25. $this->settings['actual_path'] = $path;
  26. }
  27. }
  28. public function optionsForm($delta, $qt) {
  29. $tab = $this->settings;
  30. $form = array();
  31. $form['callback']['path'] = array(
  32. '#type' => 'textfield',
  33. '#default_value' => isset($tab['path']) ? $tab['path'] : '',
  34. '#title' => t('Path'),
  35. '#element_validate' => array('quicktabs_callback_element_validate'),
  36. );
  37. return $form;
  38. }
  39. public function render($hide_empty = FALSE, $args = array()) {
  40. if ($this->rendered_content) {
  41. return $this->rendered_content;
  42. }
  43. $item = $this->settings;
  44. if (!empty($args)) {
  45. // The args have been passed in from an ajax request.
  46. // The first element of the args array is the qt_name, which we don't need
  47. // for this content type.
  48. array_shift($args);
  49. $item['actual_path'] = rawurldecode($args[0]);
  50. $_GET['q'] = $item['actual_path'];
  51. }
  52. $output = array();
  53. if (isset($item['actual_path'])) {
  54. // Retain the current page title as we'll need to set it back after
  55. // calling menu_execute_active_handler().
  56. $page_title = drupal_get_title();
  57. $response = menu_execute_active_handler($item['actual_path'], FALSE);
  58. // Revert the page title.
  59. drupal_set_title($page_title);
  60. if (!is_array($response)) {
  61. if (is_int($response)) {
  62. if (MENU_ACCESS_DENIED == $response && !$hide_empty) {
  63. $output['#markup'] = theme('quicktabs_tab_access_denied', array('tab' => $item));
  64. }
  65. // For any other integer response form the menu callback, we'll just
  66. // return an empty array.
  67. }
  68. else {
  69. $output = array('#markup' => $response);
  70. }
  71. }
  72. else {
  73. $output = $response;
  74. }
  75. }
  76. $this->rendered_content = $output;
  77. return $output;
  78. }
  79. public function getAjaxKeys() {
  80. return array('ajax_path');
  81. }
  82. }