Exemple #1
0
 /**
  * Implements hook_form_alter().
  */
 public static function doFormNodeTypeFormAlterSubmit(&$form, &$form_state)
 {
     $ntypes = variable_get('node_expire_ntypes', array());
     $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
     if ($handle_content_expiry != 0) {
         $ntypes[$form_state['values']['type']]['enabled'] = $form_state['values']['node_expire_type_cfg_enabled'];
     }
     // TODO: replace ['node_expire'] => ['node_expire_default'],
     // after that optimize.
     $ntypes[$form_state['values']['type']]['default'] = TimestampUtils::dateStrToCfgDefault($form_state['values']['node_expire_type_cfg_default']);
     $ntypes[$form_state['values']['type']]['max'] = TimestampUtils::dateStrToCfgDefault($form_state['values']['node_expire_type_cfg_max']);
     $ntypes[$form_state['values']['type']]['required'] = $form_state['values']['node_expire_type_cfg_required'];
     $ntypes[$form_state['values']['type']]['action_type'] = ActionsHelper::filterForRules($form_state['values']['node_expire_type_cfg_action_type']);
     variable_set('node_expire_ntypes', $ntypes);
     ModuleUtils::doVariablesCleanup();
 }
 /**
  * Implements hook_node_update() and hook_node_insert().
  */
 private static function doNodeUpdateInsert(&$ntype, $node)
 {
     $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
     if ($handle_content_expiry == 0) {
         // Old (legacy) style of processing.
         // Has the expiration been removed, or does it exist?
         if (isset($node->expire)) {
             DbHandler::deleteNodeExpire($node->nid);
             // Should we create a new record?
             if ($node->expire) {
                 if (strtotime($node->expire)) {
                     $node->expire = strtotime($node->expire);
                 }
                 $node->expired = FALSE;
                 drupal_write_record('node_expire', $node);
             }
         }
     } else {
         if (!isset($ntype['enabled']) || !$ntype['enabled']) {
             return;
         }
         // Create a proper $node_expire stdClass.
         $node_expire = new \stdClass();
         $node_expire->nid = $node->nid;
         // For compatibility with Node Clone module.
         // Set default $node->expire value if it is not set.
         if (!isset($node->expire)) {
             // _node_expire_node_prepare($ntype, $node);
             self::doNodePrepare($ntype, $node);
         }
         // Expire.
         $date_expire = TimestampUtils::dateStrToDb($node->expire, $ntype);
         $node_expire->expire = $date_expire;
         // Lastnotify.
         if (isset($node->lastnotify)) {
             $node_expire->lastnotify = $node->lastnotify;
         } else {
             // Default value.
             $node_expire->lastnotify = 0;
         }
         // Expired.
         if (isset($node->expired)) {
             $node_expire->new_record = 0;
             $node_expire->expired = $node->expired;
             if ($node_expire->expire >= NODE_EXPIRE_NO_EXPIRE) {
                 // No expiry for this node.
                 $node_expire->expired = 0;
             }
         } elseif (isset($node->original->expired)) {
             // For VBO (Views Bulk Operations) compatibility.
             // With VBO it is necessary to get all Node expire information
             // from $node->original instead of $node.
             $node_expire->new_record = 0;
             $node_expire->expired = $node->original->expired;
             // Also get other Node expire values.
             // Expire.
             $date_expire = TimestampUtils::dateStrToDb($node->original->expire, $ntype);
             $node_expire->expire = $date_expire;
             // Lastnotify.
             if (isset($node->original->lastnotify)) {
                 $node_expire->lastnotify = $node->original->lastnotify;
             } else {
                 // Default value.
                 $node_expire->lastnotify = 0;
             }
             if ($node_expire->expire >= NODE_EXPIRE_NO_EXPIRE) {
                 // No expiry for this node.
                 $node_expire->expired = 0;
             }
         } else {
             // No record in the database yet.
             $node_expire->new_record = 1;
             // Default value.
             $node_expire->expired = 0;
         }
         // Write the record.
         DbHandler::writeRecord($node_expire, $node->nid);
     }
 }
 /**
  * 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);
     }
 }