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)); } // $nids = array(); foreach ($result as $record) { // $nids[] = $record->nid; node_expire_set_expired($record->nid); $node = node_load($record->nid); rules_invoke_event('node_expired', $node); } } /** * Implements hook_menu(). */ 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; } /** * Implements hook_form_alter(). * * Adds expiration options to the node entry forms */ 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); } } /** * Implements hook_form_alter(). * * Enable/Disable expiration feature on node types */ 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'], ); // Visibility. $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, ); // Text fields. $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 strtotime format.'), '#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 strtotime format.') . ' ' . 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 strtotime format.') . ' ' . 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 strtotime format.') . ' ' . 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']), ); } // Add special validate/submit functions. 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'; } } /** * Implements hook_node_load(). */ function node_expire_node_load($nodes, $types) { module_load_include('nodeapi.inc', 'node_expire'); // _node_expire_node_load($ntypes, $nodes, $types); _node_expire_node_load($nodes, $types); } /** * Implements hook_node_prepare(). */ function node_expire_node_prepare($node) { // Only deal with node types that have the Node expire feature enabled. $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); } /** * Implements hook_node_validate(). */ function node_expire_node_validate($node) { // Only deal with node types that have the Node expire feature enabled. $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); } /** * Implements hook_nodeapi_update(). */ function node_expire_node_update($node) { // Only deal with node types that have the Node expire feature enabled. $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); } /** * Implements hook_nodeapi_insert(). */ function node_expire_node_insert($node) { // Only deal with node types that have the Node expire feature enabled. $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); } /** * Implements hook_nodeapi_delete(). */ function node_expire_node_delete($node) { // Only deal with node types that have the Node expire feature enabled. $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); } /** * Implements hook_permission(). */ 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.'), ), ); } /** * Implements hook_views_api(). */ function node_expire_views_api() { return array( 'api' => 2, 'path' => drupal_get_path('module', 'node_expire'), ); } /** * Sets expired values. * * @param int $nid * Node ID that should set the expired flag. */ 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(); } /** * Gets condition for date entry elements. * * This depends on value of variable node_expire_date_entry_elements * and also is date_popup module of date module installed or not. * * @return int * 0 - use text fields * 1 - use date popups */ function _node_expire_get_date_entry_elements() { // No date_popup module. if (!module_exists('date_popup')) { return 0; } // Legacy mode. if (variable_get('node_expire_handle_content_expiry', 2) == 0) { return 0; } return variable_get('node_expire_date_entry_elements', 0); } /** * Utility to display debug info. * * Display debug info and write it into log. * * @param object $data * Data to display. */ function node_expire_debug($data = array()) { drupal_set_message(filter_xss_admin('
' . print_r($data, TRUE) . '
')); watchdog('node_expire', '
' . print_r($data, TRUE) . '
'); } module_load_include('ntype.inc', 'node_expire');