View source
<?php
define('NODE_EXPIRE_FORMAT', 'Y-m-d');
define('NODE_EXPIRE_FORMAT_JS', 'yy-mm-dd');
define('NODE_EXPIRE_NO_EXPIRE', 2145934800);
function node_expire_cron() {
$handle_content_expiry = variable_get('node_expire_handle_content_expiry', 2);
if ($handle_content_expiry != 2) {
$result = db_query('SELECT n.nid FROM {node} n
JOIN {node_expire} ne ON n.nid = ne.nid
WHERE ne.expire <= :ne_expire', array(
':ne_expire' => REQUEST_TIME,
));
}
else {
$result = db_query('SELECT n.nid FROM {node} n
JOIN {node_expire} ne ON n.nid = ne.nid
WHERE ne.expire <= :ne_expire AND ne.expired = 0', array(
':ne_expire' => REQUEST_TIME,
));
}
foreach ($result as $record) {
node_expire_set_expired($record->nid);
$node = node_load($record->nid);
rules_invoke_event('node_expired', $node);
}
}
function node_expire_menu() {
$items['admin/config/workflow/node_expire/settings'] = array(
'title' => 'Node Expire',
'description' => 'Configure node expire xettings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'node_expire_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'node_expire.admin.inc',
'weight' => 2,
);
return $items;
}
function node_expire_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['type']) && (isset($form['type']['#value']) && is_string($form['type']['#value'])) && $form['type']['#value'] . '_node_form' == $form_id && ($ntypes = variable_get('node_expire_ntypes', array())) && isset($ntypes[$form['type']['#value']]) && ($ntype = $ntypes[$form['type']['#value']])) {
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_form_alter_nodeform($ntype, $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());
$node_type = $form['#node_type']->type;
$handle_content_expiry = variable_get('node_expire_handle_content_expiry', 2);
if ($handle_content_expiry != 0) {
$form['workflow']['node_expire_enabled'] = array(
'#title' => t('Enable Node Expiry'),
'#description' => t('Allow nodes to expire after a certain amount of time.'),
'#type' => 'checkbox',
'#default_value' => empty($ntypes[$node_type]['enabled']) ? '' : $ntypes[$node_type]['enabled'],
);
$states = array(
'visible' => array(
':input[name="node_expire_enabled"]' => array(
'checked' => TRUE,
),
),
);
$form['workflow']['node_expire_container'] = array(
'#type' => 'fieldset',
'#title' => t('Node Expire'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#states' => $states,
);
$form['workflow']['node_expire_container']['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>.'),
'#type' => 'textfield',
'#default_value' => empty($ntypes[$node_type]['default']) ? '' : $ntypes[$node_type]['default'],
'#states' => $states,
);
$form['workflow']['node_expire_container']['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[$node_type]['max']) ? '' : $ntypes[$node_type]['max'],
'#states' => $states,
);
$form['workflow']['node_expire_container']['node_expire_required'] = array(
'#title' => t('Expiration date required'),
'#type' => 'checkbox',
'#default_value' => !empty($ntypes[$node_type]['required']),
'#states' => $states,
);
}
else {
$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[$node_type]['default']) ? '' : $ntypes[$node_type]['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[$node_type]['max']) ? '' : $ntypes[$node_type]['max'],
);
$form['workflow']['node_expire_required'] = array(
'#title' => t('Expiration date required'),
'#type' => 'checkbox',
'#default_value' => !empty($ntypes[$node_type]['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_node_load($nodes, $types) {
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_node_load($nodes, $types);
}
function node_expire_node_prepare($node) {
$ntypes = variable_get('node_expire_ntypes', array());
if (!isset($ntypes[$node->type])) {
return;
}
if (!($ntype = $ntypes[$node->type])) {
return;
}
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_node_prepare($ntype, $node);
}
function node_expire_node_validate($node) {
$ntypes = variable_get('node_expire_ntypes', array());
if (!isset($ntypes[$node->type])) {
return;
}
if (!($ntype = $ntypes[$node->type])) {
return;
}
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_node_validate($ntype, $node);
}
function node_expire_node_update($node) {
$ntypes = variable_get('node_expire_ntypes', array());
if (!isset($ntypes[$node->type])) {
return;
}
if (!($ntype = $ntypes[$node->type])) {
return;
}
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_node_update_insert($ntype, $node);
}
function node_expire_node_insert($node) {
$ntypes = variable_get('node_expire_ntypes', array());
if (!isset($ntypes[$node->type])) {
return;
}
if (!($ntype = $ntypes[$node->type])) {
return;
}
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_node_update_insert($ntype, $node);
}
function node_expire_node_delete($node) {
$ntypes = variable_get('node_expire_ntypes', array());
if (!isset($ntypes[$node->type])) {
return;
}
if (!($ntype = $ntypes[$node->type])) {
return;
}
module_load_include('nodeapi.inc', 'node_expire');
_node_expire_node_delete($ntype, $node);
}
function node_expire_permission() {
return array(
'administer node expire' => array(
'title' => t('Administer node expire'),
'description' => t('Administer node expire functionality.'),
),
'edit node expire' => array(
'title' => t('Edit node expire'),
'description' => t('Edit node expiration dates.'),
),
);
}
function node_expire_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'node_expire'),
);
}
function node_expire_set_expired($nid) {
db_update('node_expire')
->fields(array(
'expired' => 1,
'lastnotify' => REQUEST_TIME,
))
->condition('nid', $nid)
->condition(db_or()
->condition('lastnotify', 0)
->condition('expired', 1, '!='))
->execute();
}
function _node_expire_get_date_entry_elements() {
if (!module_exists('date_popup')) {
return 0;
}
if (variable_get('node_expire_handle_content_expiry', 2) == 0) {
return 0;
}
return variable_get('node_expire_date_entry_elements', 0);
}
function node_expire_debug($data = array()) {
drupal_set_message(filter_xss_admin('<pre>' . print_r($data, TRUE) . '</pre>'));
watchdog('node_expire', '<pre>' . print_r($data, TRUE) . '</pre>');
}
module_load_include('ntype.inc', 'node_expire');