1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains rules integration for the node module needed during evaluation.
|
6
|
*
|
7
|
* @addtogroup rules
|
8
|
* @{
|
9
|
*/
|
10
|
|
11
|
/**
|
12
|
* Base class providing node condition defaults.
|
13
|
*/
|
14
|
abstract class RulesNodeConditionBase extends RulesConditionHandlerBase {
|
15
|
|
16
|
public static function defaults() {
|
17
|
return array(
|
18
|
'parameter' => array(
|
19
|
'node' => array('type' => 'node', 'label' => t('Content')),
|
20
|
),
|
21
|
'category' => 'node',
|
22
|
'access callback' => 'rules_node_integration_access',
|
23
|
);
|
24
|
}
|
25
|
}
|
26
|
|
27
|
/**
|
28
|
* Condition: Check for selected content types
|
29
|
*/
|
30
|
class RulesNodeConditionType extends RulesNodeConditionBase {
|
31
|
|
32
|
/**
|
33
|
* Defines the condition.
|
34
|
*/
|
35
|
public static function getInfo() {
|
36
|
$info = self::defaults() + array(
|
37
|
'name' => 'node_is_of_type',
|
38
|
'label' => t('Content is of type'),
|
39
|
'help' => t('Evaluates to TRUE if the given content is of one of the selected content types.'),
|
40
|
);
|
41
|
$info['parameter']['type'] = array(
|
42
|
'type' => 'list<text>',
|
43
|
'label' => t('Content types'),
|
44
|
'options list' => 'node_type_get_names',
|
45
|
'description' => t('The content type(s) to check for.'),
|
46
|
'restriction' => 'input',
|
47
|
);
|
48
|
return $info;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Executes the condition.
|
53
|
*/
|
54
|
public function execute($node, $types) {
|
55
|
return in_array($node->type, $types);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Provides the content type of a node as asserted metadata.
|
60
|
*/
|
61
|
function assertions() {
|
62
|
return array('node' => array('bundle' => $this->element->settings['type']));
|
63
|
}
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Condition: Check if the node is published.
|
68
|
*/
|
69
|
class RulesNodeConditionPublished extends RulesNodeConditionBase {
|
70
|
|
71
|
/**
|
72
|
* Defines the condition.
|
73
|
*/
|
74
|
public static function getInfo() {
|
75
|
return self::defaults() + array(
|
76
|
'name' => 'node_is_published',
|
77
|
'label' => t('Content is published'),
|
78
|
);
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* Executes the condition.
|
83
|
*/
|
84
|
public function execute($node) {
|
85
|
return $node->status == 1;
|
86
|
}
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Condition: Check if the node is sticky.
|
91
|
*/
|
92
|
class RulesNodeConditionSticky extends RulesNodeConditionBase {
|
93
|
|
94
|
/**
|
95
|
* Defines the condition.
|
96
|
*/
|
97
|
public static function getInfo() {
|
98
|
return self::defaults() + array(
|
99
|
'name' => 'node_is_sticky',
|
100
|
'label' => t('Content is sticky'),
|
101
|
);
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Executes the condition.
|
106
|
*/
|
107
|
public function execute($node) {
|
108
|
return $node->sticky == 1;
|
109
|
}
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Condition: Check if the node is promoted to the frontpage
|
114
|
*/
|
115
|
class RulesNodeConditionPromoted extends RulesNodeConditionBase {
|
116
|
|
117
|
/**
|
118
|
* Defines the condition.
|
119
|
*/
|
120
|
public static function getInfo() {
|
121
|
return self::defaults() + array(
|
122
|
'name' => 'node_is_promoted',
|
123
|
'label' => t('Content is promoted to frontpage'),
|
124
|
);
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* Executes the condition.
|
129
|
*/
|
130
|
public function execute($node) {
|
131
|
return $node->promote == 1;
|
132
|
}
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* @}
|
137
|
*/
|