/**
  * Implements hook_node_load().
  */
 private static function doNodeLoad($nodes, $types)
 {
     // Only deal with node types that have the Node expire feature enabled.
     $ntypes = variable_get('node_expire_ntypes', array());
     $node_expire_enabled = array();
     // Check if node_expire are enabled for each node.
     // If node_expires are not enabled, do nothing.
     foreach ($nodes as $node) {
         // Store whether node_expires are enabled for this node.
         if (isset($ntypes[$node->type]) and $ntypes = $ntypes[$node->type]) {
             $node_expire_enabled[] = $node->nid;
         }
     }
     // For nodes with node_expire enabled, fetch information from the database.
     if (!empty($node_expire_enabled)) {
         $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
         $result = DbHandler::selectForNodeLoad($node_expire_enabled);
         foreach ($result as $record) {
             if ($handle_content_expiry == 0) {
                 $nodes[$record->nid]->expire = $record->expire;
             } else {
                 $ntype = isset($ntypes[$record->type]) ? $ntypes[$record->type] : NULL;
                 $nodes[$record->nid]->expire = TimestampUtils::dateDbToStr($record->expire, $ntype);
             }
             $nodes[$record->nid]->expired = $record->expired;
             $nodes[$record->nid]->lastnotify = $record->lastnotify;
         }
     }
 }
 /**
  * Implements hook_form_alter().
  *
  * Adds expiration options to the node entry forms.
  */
 private static function doFormAlter(&$ntype, &$form, &$form_state, $form_id)
 {
     // Check if the Node expire feature is enabled for the node type.
     $node = isset($form['#node']) ? $form['#node'] : NULL;
     $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
     if ($handle_content_expiry != 0) {
         if (empty($ntype['enabled'])) {
             return;
         }
         // Replace not set to default string.
         if (!isset($node->expire)) {
             // $ntype = isset($ntypes[$node->type]) ? $ntypes[$node->type] : NULL;
             $node->expire = TimestampUtils::dateDbToStr('', $ntype);
         }
     } else {
         // Replace not set to empty string.
         if (!isset($node->expire)) {
             $node->expire = '';
         }
         // Convert the timestamp into a human readable date - legacy branch.
         if (is_numeric($node->expire)) {
             $node->expire = format_date($node->expire, 'custom', ConfigHandler::getDateFormat());
         }
     }
     // This supports node to never expire.
     if (empty($ntype['default']) && empty($node->expire)) {
         $ntype['required'] = FALSE;
     }
     if (user_access('edit node expire')) {
         if (ConfigHandler::getDateEntryElements()) {
             // Date popups.
             // TODO: Edit format description sting.
             $expire_field = array('#title' => t('Expiration date'), '#description' => t('Time date to consider the node expired. Format: %time (%format).', array('%time' => format_date(REQUEST_TIME, 'custom', ConfigHandler::getDateFormat()), '%format' => ConfigHandler::getDateFormat())), '#type' => 'date_popup', '#date_format' => ConfigHandler::getDateFormat(), '#required' => $ntype['required'], '#default_value' => $node->expire);
         } else {
             // Text fields.
             // TODO: Edit format description sting.
             $expire_field = array('#title' => t('Expiration date'), '#description' => t('Time date to consider the node expired. Format: %time (%format).', array('%time' => format_date(REQUEST_TIME, 'custom', ConfigHandler::getDateFormat()), '%format' => ConfigHandler::getDateFormat())), '#type' => 'textfield', '#maxlength' => 25, '#required' => $ntype['required'], '#default_value' => $node->expire);
         }
     } else {
         $expire_field = array('#type' => 'value', '#value' => $node->expire);
     }
     // If we use hidden value, do not create fieldset.
     if ($expire_field['#type'] == 'value') {
         $form['options1'] = array();
         $form['options1']['expire'] =& $expire_field;
     } elseif (!$form['options']['#access']) {
         $form['options1'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => 95);
         $form['options1']['expire'] =& $expire_field;
     } else {
         $form['options']['expire'] =& $expire_field;
     }
     if (isset($node->expired)) {
         $form['node_expire'] = array('#type' => 'value', '#value' => TRUE);
     }
 }