View source
<?php
DEFINE('NODE_EXPIRE_FORMAT', 'Y-m-d');
DEFINE('NODE_EXPIRE_FORMAT_JS', 'yy-mm-dd');
function node_expire_cron() {
if ($query = db_query('SELECT n.nid FROM {node} n
JOIN {node_expire} ne ON n.nid = ne.nid
WHERE ne.expire <= %d', time())) {
$nids = array();
while ($node = db_fetch_object($query)) {
$nids[] = $node->nid;
node_expire_set_expired($node->nid);
$node = node_load($node->nid);
rules_invoke_event('node_expired', array(
'node' => &$node,
));
}
}
}
function node_expire_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['type']) and $form['type']['#value'] . '_node_form' == $form_id and $ntypes = variable_get('node_expire_ntypes', array()) and $ntypes = $ntypes[$form['type']['#value']]) {
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_form_alter_nodeform($ntypes, $form, $form_state, $form_id);
}
}
function node_expire_form_node_type_form_alter(&$form, &$form_state) {
if (user_access('administer node expire')) {
$ntypes = variable_get('node_expire_ntypes', array());
$ntype = $form['#node_type']->type;
$form['workflow']['node_expire'] = array(
'#title' => t('Default expiration date'),
'#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.'),
'#type' => 'textfield',
'#default_value' => empty($ntypes[$ntype]['default']) ? '' : $ntypes[$ntype]['default'],
);
$form['workflow']['node_expire_max'] = array(
'#title' => t('Expiration date limit'),
'#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.'),
'#type' => 'textfield',
'#default_value' => empty($ntypes[$ntype]['max']) ? '' : $ntypes[$ntype]['max'],
);
$form['workflow']['node_expire_required'] = array(
'#title' => t('Expiration date required'),
'#type' => 'checkbox',
'#default_value' => !empty($ntypes[$ntype]['required']),
);
module_load_include('ntype.inc', 'node_expire');
$form['#validate'][] = '_node_expire_form_node_type_form_alter_validate';
$form['#submit'][] = '_node_expire_form_node_type_form_alter_submit';
}
}
function node_expire_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$ntypes = variable_get('node_expire_ntypes', array());
if (!($ntypes = $ntypes[$node->type])) {
return;
}
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_nodeapi($ntypes, $node, $op, $a3, $a4);
}
function node_expire_perm() {
return array(
'administer node expire',
'edit node expire',
);
}
function node_expire_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'node_expire'),
);
}
function node_expire_set_expired($nid) {
db_query("UPDATE {node_expire} SET expired = '1', lastnotify = '" . time() . "' WHERE nid = '" . $nid . "' AND (lastnotify = '0' || expired != '1')");
}