function classified_validate in Classified Ads 7.3
Same name and namespace in other branches
- 6.3 classified.module \classified_validate()
Implements hook_validate().
- accept empty expiration dates,
- accept dates in site-specific format only, and only after current time.
File
- ./
classified.module, line 1676 - A pure D7 classified ads module inspired by the ed_classified module.
Code
function classified_validate($node, &$form) {
// Coder bug #195054.
$mode = $form['expires_fs']['expire_mode']['#value'];
// Coder bug #195054.
$date = $form['expires_fs']['expire_date']['#value'];
$date = _classified_get_timestamp_from_date($date);
// This can be a user error, as the max_length JS is not being included if
// form_set_error has been used.
$max_length = _classified_get('max-length');
// Body may include <!--break-->, possibly wrapped with spaces (newlines),
// which must not be included in the length count.
$body = isset($node->body[LANGUAGE_NONE][0]['value']) ? $node->body[LANGUAGE_NONE][0]['value'] : NULL;
$body = preg_replace('/^(.*)\\s*<!--break-->\\s*(.*)$/sU', '$1$2', $body);
// Ignore \r, only count \n.
$body = str_replace("\r\n", "\n", $body);
$body_length = drupal_strlen($body);
if ($max_length > 0 && $body_length > $max_length) {
form_set_error('body', t('Text is longer than maximum authorized length: @body_length characters vs @max_length authorized.', array(
'@body_length' => $body_length,
'@max_length' => $max_length,
)));
}
// This is likely a hacking attempt.
if ($mode == 'force' && !user_access('administer classified ads') && !user_access('reset classified ads expiration')) {
form_set_error('expire_mode', t('User is not allowed to force expiration date.'));
global $user;
watchdog('classified', 'Attempt by user @uid to force expiration reset on ad @nid: @title', array(
'@uid' => $user->uid,
'@nid' => $node->nid,
'@title' => $node->title,
), WATCHDOG_WARNING, l($user->name, 'user/' . $user->uid) . l($node->title, ' node/' . $node->nid));
}
// This is likely just a user error.
if ($mode == 'force' && $date < REQUEST_TIME) {
form_set_error('expire_date', t('Invalid expiration date: before now.'));
}
}