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

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents
children 134d4b2e75f6
comparison
equal deleted inserted replaced
1:67ce89da90df 2:b74b41bb73f0
1 <?php
2
3 /**
4 * Class for tab content of type "view" - this is for rendering a view as tab
5 * content.
6 */
7 class QuickViewContent extends QuickContent {
8
9 // Each view that we render, whether via ajax or not, will need a unique DOM
10 // id. Unfortunately we can only control the ones that Quicktabs is responsible
11 // for, so if there are other views on the page, there may be duplicate ids.
12 static $view_dom_id = 1;
13
14 public static function getType() {
15 return 'view';
16 }
17
18 public function optionsForm($delta, $qt) {
19 $tab = $this->settings;
20 $form = array();
21 $views = quicktabs_get_views();
22 $views_keys = array_keys($views);
23
24 $selected_view = (isset($tab['vid']) ? $tab['vid'] : (isset($views_keys[0]) ? $views_keys[0] : ''));
25 $form['view']['vid'] = array(
26 '#type' => 'select',
27 '#options' => $views,
28 '#default_value' => $selected_view,
29 '#title' => t('Select a view'),
30 '#ajax' => array(
31 'callback' => '_quicktabs_replace_view_displays_callback',
32 ),
33 );
34 $form['view']['display'] = array(
35 '#type' => 'select',
36 '#title' => 'display',
37 '#options' => _quicktabs_get_views_displays($selected_view),
38 '#default_value' => isset($tab['display']) ? $tab['display'] : '',
39 '#prefix' => '<div id="view-display-dropdown-' . $delta . '">',
40 '#suffix' => '</div>'
41 );
42 $form['view']['args'] = array(
43 '#type' => 'textfield',
44 '#title' => 'arguments',
45 '#size' => '40',
46 '#required' => FALSE,
47 '#default_value' => isset($tab['args']) ? $tab['args'] : '',
48 '#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.'),
49 );
50 return $form;
51 }
52
53 public function __construct($item) {
54 parent::__construct($item);
55 if (module_exists('views')) views_add_js('ajax_view');
56 $this->settings['view_path'] = rawurlencode($_GET['q']);
57 $this->settings['view_dom_id'] = self::$view_dom_id++;
58 if (isset($item['args'])) {
59 $url_args = arg();
60 $args = $item['args'];
61
62 foreach ($url_args as $id => $arg) {
63 $args = str_replace("%$id", $arg, $args);
64 }
65 $args = preg_replace(',/?(%\d),', '', $args);
66 if (!empty($args)) {
67 $this->settings['ajax_args'] = rawurlencode($args);
68 $args_array = explode('/', $args);
69 }
70 else {
71 $this->settings['ajax_args'] = '';
72 $args_array = array();
73 }
74 $this->settings['actual_args'] = $args_array;
75 }
76 }
77
78 public function render($hide_empty = FALSE, $args = array()) {
79 if (!empty($args)) {
80 // The args have been passed in from an ajax request. We use Views' own
81 // ajax functionality to get the view.
82 // The first element of the args array is the qt_name, which we don't need
83 // for this content type.
84 array_shift($args);
85 // The order of these arguments corresponds to the array returned in
86 // $this->getAjaxKeys().
87 $_REQUEST['view_name'] = array_shift($args);
88 $_REQUEST['view_display_id'] = array_shift($args);
89 $_REQUEST['view_dom_id'] = array_shift($args);
90 $view_path = array_shift($args);
91 $_REQUEST['view_path'] = rawurldecode($view_path);
92 if (!empty($args)) {
93 $view_args = array_shift($args);
94 $_REQUEST['view_args'] = rawurldecode($view_args);
95 }
96
97 module_load_include('inc', 'views', 'includes/ajax');
98 $view = views_ajax();
99 foreach ($view['#commands'] as $command) {
100 if ($command['command'] == 'insert') {
101 return array('#markup' => trim($command['data']));
102 }
103 }
104 return array();
105 }
106
107 // Non-ajax rendering of a view.
108 if ($this->rendered_content) {
109 return $this->rendered_content;
110 }
111 $item = $this->settings;
112 $output = array();
113 if (isset($item['vid'])) {
114 if (module_exists('views')) {
115 if ($view = views_get_view($item['vid'])) {
116 if ($view->access($item['display'])) {
117 $view->set_display($item['display']);
118 $view->set_arguments($item['actual_args']);
119 $view_output = $view->preview();
120 if (!empty($view->result) || $view->display_handler->get_option('empty') || !empty($view->style_plugin->definition['even empty'])) {
121 $output['#markup'] = $view_output;
122 }
123 }
124 elseif (!$hide_empty) {
125 $output['#markup'] = theme('quicktabs_tab_access_denied', array('tab' => $item));
126 }
127 $view->destroy();
128 }
129 }
130 elseif (!$hide_empty) {
131 $output['#markup'] = t('Views module is not enabled, cannot display content.');
132 }
133 }
134 $this->rendered_content = $output;
135 return $output;
136 }
137
138 public function getAjaxKeys() {
139 return array('vid', 'display', 'view_dom_id', 'view_path', 'ajax_args');
140 }
141 }