1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Rules integration of the mimemail and the PDF Views module.
|
6 |
|
|
*
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Implements hook_rules_action_info().
|
11 |
|
|
*/
|
12 |
|
|
function views_pdf_rules_action_info() {
|
13 |
|
|
|
14 |
|
|
$items = array();
|
15 |
|
|
|
16 |
|
|
$items['views_pdf_rules_action_save'] = array(
|
17 |
|
|
'label' => t('Save PDF as file on server'),
|
18 |
|
|
'group' => t('Views PDF'),
|
19 |
|
|
'parameter' => array(
|
20 |
|
|
'views_pdf' => array(
|
21 |
|
|
'type' => 'text',
|
22 |
|
|
'label' => t('View'),
|
23 |
|
|
'options list' => 'views_pdf_rules_view_list',
|
24 |
|
|
'description' => t('You need to enter the View and the Display to use. Use the ids of them and separate them by a ":".'),
|
25 |
|
|
),
|
26 |
|
|
'arguments' => array(
|
27 |
|
|
'type' => 'text',
|
28 |
|
|
'label' => t('Views Arguments'),
|
29 |
|
|
'optional' => TRUE,
|
30 |
|
|
'description' => t('Place on each line one argument.')
|
31 |
|
|
),
|
32 |
|
|
'path' => array(
|
33 |
|
|
'type' => 'text',
|
34 |
|
|
'label' => t('Store Path'),
|
35 |
|
|
'optional' => FALSE,
|
36 |
|
|
'description' => t('Enter an relative path where the view should be saved. You may use some tokens.'),
|
37 |
|
|
),
|
38 |
|
|
),
|
39 |
|
|
);
|
40 |
|
|
|
41 |
|
|
return $items;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
function views_pdf_rules_view_list() {
|
45 |
|
|
$views = views_get_all_views();
|
46 |
|
|
|
47 |
|
|
$list = array();
|
48 |
|
|
|
49 |
|
|
foreach ($views as $view => $view_object) {
|
50 |
|
|
foreach ($view_object->display as $display => $display_object) {
|
51 |
|
|
if ($display_object->display_plugin == 'pdf') {
|
52 |
|
|
$list[$view . ':' . $display] = $view_object->human_name . ': ' . $display_object->display_title;
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
return $list;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
function views_pdf_rules_action_save($views_pdf, $arguments, $path) {
|
62 |
|
|
$splits = explode(':', $views_pdf);
|
63 |
|
|
$view_id = $splits[0];
|
64 |
|
|
$display_id = $splits[1];
|
65 |
|
|
|
66 |
|
|
if (!empty($view_id)) {
|
67 |
|
|
$view = views_get_view($view_id);
|
68 |
|
|
|
69 |
|
|
$view->set_arguments(explode("\n", $arguments));
|
70 |
|
|
|
71 |
|
|
// Try to get pdf display
|
72 |
|
|
if (!$view->set_display($display_id)) {
|
73 |
|
|
// Try the display type
|
74 |
|
|
if (!$view->set_display('pdf_1')) {
|
75 |
|
|
// There is definitly no pdf display
|
76 |
|
|
return;
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
$view->pre_execute();
|
81 |
|
|
foreach ($view->display as $id => $display) {
|
82 |
|
|
if ($display->display_plugin == 'pdf' && isset($display->handler)) {
|
83 |
|
|
$display->handler->execute($path, 'F');
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
}
|
88 |
|
|
} |