node.eval.inc 2.8 KB

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