You are here

function classified_preprocess_classified_expires in Classified Ads 7.3

Same name and namespace in other branches
  1. 6.3 classified.module \classified_preprocess_classified_expires()

Implements hook_preprocess_classified_expires().

Define four formats for the expiration date of a node:

  • expires: default date format for the module,
  • expires_raw: UNIX timestamp,
  • remaining: days to expiration,
  • remaining_ratio: the percentile of ad lifetime already expired.
1 call to classified_preprocess_classified_expires()
classified_classified_expires_content_type_render in plugins/content_types/classified_expires.inc
Implements hook_PLUGIN_content_type_render().

File

./classified.module, line 1493
A pure D7 classified ads module inspired by the ed_classified module.

Code

function classified_preprocess_classified_expires(&$variables) {
  $node = $variables['node'];
  $now = REQUEST_TIME;
  $expires_raw = $node->expires;
  $variables['expires_raw'] = $expires_raw;
  $date_format = _classified_get('date-format');
  $variables['expires'] = strftime($date_format, $expires_raw);
  $variables['remaining'] = format_interval($expires_raw - $now, 1);
  $remaining_ratio = $expires_raw > $now ? round(100 * (($expires_raw - $now) / ($expires_raw - $variables['node']->created))) : 0;
  $variables['remaining_ratio'] = $remaining_ratio;

  // Color-code ratios.
  if ($remaining_ratio == 0) {
    $class = 'classified-expires-expired';
  }
  elseif ($remaining_ratio < 20) {
    $class = 'classified-expires-soon';
  }
  else {
    $class = 'classified-expires-later';
  }
  $variables['remaining_class'] = $class;
}