1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Views Append Handler
|
5
|
*
|
6
|
* To append a view to another a field handler is used.
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* This class contains all the functionality to append a view to another one.
|
11
|
*
|
12
|
*/
|
13
|
class views_append_handler_append_view extends views_handler_field {
|
14
|
|
15
|
/**
|
16
|
* This method is used to query data. In our case
|
17
|
* we want that no data is queried.
|
18
|
*
|
19
|
*/
|
20
|
function query() {
|
21
|
// Override parent::query() and don't alter query.
|
22
|
$this->field_alias = 'view_append_' . $this->position;
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* This method contains the defintion of the options for appending a view.
|
27
|
*/
|
28
|
function option_definition() {
|
29
|
$options = parent::option_definition();
|
30
|
|
31
|
$options['url'] = array('default' => '');
|
32
|
|
33
|
return $options;
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* Option form
|
38
|
*/
|
39
|
function options_form(&$form, &$form_state) {
|
40
|
parent::options_form($form, $form_state);
|
41
|
|
42
|
$form['url'] = array(
|
43
|
'#type' => 'textfield',
|
44
|
'#title' => t('Enter the URL to the file'),
|
45
|
'#default_value' => $this->options['url'],
|
46
|
'#description' => t('Enter the URL to the file. You can use tokens to replace some parts of the URL.'),
|
47
|
);
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* This method renders the other view.
|
52
|
*/
|
53
|
function render($values) {
|
54
|
|
55
|
if ($this->options['exclude'] == '1') {
|
56
|
return '';
|
57
|
}
|
58
|
|
59
|
$tokens = $this->get_render_tokens('');
|
60
|
|
61
|
$url = str_replace(array_keys($tokens), $tokens, $this->options['url']);
|
62
|
$data = file_get_contents($url);
|
63
|
|
64
|
$tmp_file = md5($url . time());
|
65
|
|
66
|
$files_path = file_directory_temp();
|
67
|
$dir = $files_path . '/views_append_tmp_files';
|
68
|
|
69
|
if (!is_dir($dir)) {
|
70
|
@mkdir($dir);
|
71
|
}
|
72
|
|
73
|
if (is_writable($dir)) {
|
74
|
$path = $dir . '/' . $tmp_file;
|
75
|
views_append_request_with_cookie($url, $path);
|
76
|
|
77
|
if (isset($this->view->pdf) && is_object($this->view->pdf)) {
|
78
|
$this->view->pdf->addPdfDocument($path);
|
79
|
}
|
80
|
else {
|
81
|
return file_get_contents($path);
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* We dont want to use advanced rendering.
|
88
|
*/
|
89
|
function allow_advanced_render() {
|
90
|
return FALSE;
|
91
|
}
|
92
|
}
|