-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconvertfile.rules.inc
157 lines (145 loc) · 4.69 KB
/
convertfile.rules.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Implementation of hook_rules_event_info().
*/
function convertfile_rules_event_info() {
return array(
'convertfile_request' => array(
'group' => 'Convert File',
'label' => t('File conversion has been requested'),
'module' => 'convertfile',
'variables' => array(
'file' => array('type' => 'file', 'label' => t('The file on which compression has been requested.')),
'instance' => array('type' => 'struct', 'label' => t('Field instance that file is attached to.')),
),
),
'convertfile_success' => array(
'group' => 'Convert File',
'label' => t('File conversion has succeeded'),
'module' => 'convertfile',
'variables' => array(
'file' => array('type' => 'file', 'label' => t('The file on which compression has been requested.')),
'instance' => array('type' => 'struct', 'label' => t('Field instance that file is attached to.')),
),
),
'convertfile_failure' => array(
'group' => 'Convert File',
'label' => t('File conversion has failed'),
'module' => 'convertfile',
'variables' => array(
'file' => array('type' => 'file', 'label' => t('The file on which compression has been requested.')),
'instance' => array('type' => 'struct', 'label' => t('Field instance that file is attached to.')),
),
),
);
}
/**
* implementation of hook_rules_condition_info()
*/
function convertfile_rules_condition_info() {
return array(
'convertfile_condition_file_extension' => array(
'label' => t('Original format'),
'group' => 'Convert File',
'parameter' => array(
'file' => array('type' => 'file', 'label' => t('The file object')),
'extension' => array('type' => 'text', 'label' => t('The original extension is')),
),
'module' => 'convertfile',
),
'convertfile_condition_provider' => array(
'label' => t('Conversion provider'),
'group' => 'Convert File',
'parameter' => array(
'instance' => array('type' => 'struct', 'label' => t('File field instance')),
'provider' => array(
'type' => 'list<text>',
'label' => t('The provider is'),
'options list' => 'convertfile_condition_provider_list',
),
),
'module' => 'convertfile',
),
'convertfile_condition_format' => array(
'label' => t('Conversion format'),
'group' => 'Convert File',
'parameter' => array(
'instance' => array('type' => 'struct', 'label' => t('File field instance')),
'format' => array(
'type' => 'list<text>',
'label' => t('The requested format is'),
'options list' => 'convertfile_condition_format_list',
),
),
'module' => 'convertfile',
),
);
}
/**
* Condition convertfile_condition_file_extension
*/
function convertfile_condition_file_extension($file, $extension) {
$report = FALSE;
if (isset($file->convertfile['original']->filename)) {
$ext = pathinfo($file->convertfile['original']->filename, PATHINFO_EXTENSION);
}
else {
$ext = pathinfo($file->filename, PATHINFO_EXTENSION);
}
if ($ext == $extension) {
$report = TRUE;
}
return $report;
}
/**
* Condition convertfile_condition_provider
*/
function convertfile_condition_provider($instance, $provider) {
$report = FALSE;
$settings = $instance['widget']['settings'];
if (array_key_exists($settings['convertfile_provider'], $provider)) {
$report = TRUE;
}
return $report;
}
/**
* Condition convertfile_condition_format
*/
function convertfile_condition_format($instance, $format) {
$report = FALSE;
$settings = $instance['widget']['settings'];
if (array_key_exists($settings['convertfile_ajax']['convertfile_format'], $format)) {
$report = TRUE;
}
return $report;
}
/**
* Construct options list for condition convertfile_condition_provider.
*
* @see convertfile_rules_condition_info()
*/
function convertfile_condition_provider_list(RulesAbstractPlugin $element) {
$providers = array('convertfile_none' => '- None -');
if (is_array($info = convertfile_collect_info())) {
foreach($info as $machine_name => $provider) {
$providers[$machine_name] = $provider['name'];
}
}
return $providers;
}
/**
* Construct options list for condition convertfile_condition_format.
*
* @see convertfile_rules_condition_info()
*/
function convertfile_condition_format_list(RulesAbstractPlugin $element) {
$formats = array('convertfile_none' => '- None -');
if (is_array($info = convertfile_collect_info())) {
foreach($info as $mn_provider => $provider) {
foreach($provider['types'] as $mn_type => $type) {
$formats[$mn_type] = $type;
}
}
}
return $formats;
}