You are here

function simpleads_node_presave in SimpleAds 7.2

Same name and namespace in other branches
  1. 7 simpleads.module \simpleads_node_presave()

Implements hook_node_presave().

File

includes/node.inc, line 74
SimpleAds node.

Code

function simpleads_node_presave($node) {

  // Make sure this advertisement not in campaign.
  if (!isset($node->field_adcamp_list[$node->language][0])) {
    if (isset($node->field_ad_date[$node->language]) && isset($node->field_ad_date[$node->language][0])) {

      // Advertisement start date.
      $start_date = strtotime($node->field_ad_date[$node->language][0]['value']);

      // Advertisetment end date.
      $end_date = strtotime($node->field_ad_date[$node->language][0]['value2']);

      // Show end date indicator.
      $show_to_date = isset($node->field_ad_date[$node->language][0]['show_todate']) ? $node->field_ad_date[$node->language][0]['show_todate'] : FALSE;

      // Change node status if start date already occured.
      if ($start_date < REQUEST_TIME && $node->status == 0) {
        $node->status = 1;
      }

      // If advertisement start date in the future, unpublish it and wait when the start date occurs.
      if ($start_date > REQUEST_TIME && $node->status == 1) {
        $node->status = 0;
      }

      // Unpublish advertisement if end date occured.
      if ($end_date < REQUEST_TIME && $node->status == 1 && $show_to_date) {
        $node->status = 0;
      }
    }
  }
}