comparison sites/all/modules/quicktabs/plugins/QuickCallbackContent.inc @ 2:b74b41bb73f0

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