/[drupal]/contributions/modules/node_expire/node_expire.module
ViewVC logotype

Contents of /contributions/modules/node_expire/node_expire.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sat Jan 31 01:26:53 2009 UTC (9 months, 3 weeks ago) by brmassa
Branch: MAIN
CVS Tags: DRUPAL-6--2-03, HEAD
Changes since 1.8: +6 -1 lines
File MIME type: text/x-php
New features:
* Node expiration REQUIRE option
1 <?php
2 // $Id: node_expire.module,v 1.8 2009/01/29 21:01:33 brmassa Exp $
3
4 /**
5 * @file
6 * Set a timer into your content, allowing you to perform customized actions.
7 */
8
9 DEFINE('NODE_EXPIRE_FORMAT', 'Y-m-d');
10 DEFINE('NODE_EXPIRE_FORMAT_JS', 'yy-mm-dd');
11
12 /**
13 * Implementation of hook_cron().
14 */
15 function node_expire_cron() {
16 if ($query = db_query('SELECT n.nid FROM {node} n
17 JOIN {node_expire} ne ON n.nid = ne.nid
18 WHERE ne.expired = 0 AND ne.expire <= %d', time())) {
19 while ($node = db_fetch_object($query)) {
20 $nids[] = $node->nid;
21 $node = node_load($node->nid);
22 rules_invoke_event('node_expired', array('node' => &$node));
23 }
24 module_load_include('rules.inc', 'node_expire');
25 node_expire_set_expired($nids, TRUE);
26 }
27 }
28
29 /**
30 * Implementation of hook_form_alter().
31 *
32 * Add expiration options to the node entry forms
33 */
34 function node_expire_form_alter(&$form, &$form_state, $form_id) {
35 if (isset($form['type'])
36 and $form['type']['#value'] .'_node_form' == $form_id
37 and $ntypes = variable_get('node_expire_ntypes', array())
38 and $ntypes = $ntypes[$form['type']['#value']]) {
39
40 module_load_include('nodeapi.inc', 'node_expire');
41 _node_expire_form_alter_nodeform($ntypes, $form, $form_state, $form_id);
42 }
43 }
44
45 /**
46 * Implementation of hook_form_alter().
47 *
48 * Enable/Disable expiration feature on node types
49 */
50 function node_expire_form_node_type_form_alter(&$form, &$form_state) {
51 if (user_access('administer node expire')) {
52 $ntypes = variable_get('node_expire_ntypes', array());
53 $ntype = $form['#node_type']->type;
54 $form['workflow']['node_expire'] = array(
55 '#title' => t('Expiration Date'),
56 '#description' => t('Default date to consider the node expired.') .' '. t('Format: PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>.') .' '. t('Leave it blank if this content type never expires.'),
57 '#type' => 'textfield',
58 '#default_value' => empty($ntypes[$ntype]['default']) ? '' : $ntypes[$ntype]['default'],
59 );
60 $form['workflow']['node_expire_max'] = array(
61 '#title' => t('Expiration Date Limit'),
62 '#description' => t('The max date to consider the node expired.') .' '. t('Format: PHP <a href="http://www.php.net/strtotime" target="_blank">strtotime format</a>.') .' '. t('Leave it blank if this there is no limit date.'),
63 '#type' => 'textfield',
64 '#default_value' => empty($ntypes[$ntype]['max']) ? '' : $ntypes[$ntype]['max'],
65 );
66 $form['workflow']['node_expire_required'] = array(
67 '#title' => t('Expiration Date Required'),
68 '#type' => 'checkbox',
69 '#default_value' => !empty($ntypes[$ntype]['required']),
70 );
71
72 // Add special validate/submit functions
73 module_load_include('ntype.inc', 'node_expire');
74 $form['#validate'][] = '_node_expire_form_node_type_form_alter_validate';
75 $form['#submit'][] = '_node_expire_form_node_type_form_alter_submit';
76 }
77 }
78
79 /**
80 * Implementation of hook_nodeapi().
81 */
82 function node_expire_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
83 // Only deal with node types that have the Node Expire feature enabled
84 $ntypes = variable_get('node_expire_ntypes', array());
85 if (!$ntypes = $ntypes[$node->type]) {
86 return;
87 }
88
89 module_load_include('nodeapi.inc', 'node_expire');
90 _node_expire_nodeapi($ntypes, $node, $op, $a3, $a4);
91 }
92
93 /**
94 * Implementation of hook_perm().
95 */
96 function node_expire_perm() {
97 return array('administer node expire', 'edit node expire');
98 }
99
100 /**
101 * Implementation of hook_views_api().
102 */
103 function node_expire_views_api() {
104 return array(
105 'api' => 2,
106 'path' => drupal_get_path('module', 'node_expire'),
107 );
108 }

  ViewVC Help
Powered by ViewVC 1.1.2