| 1 |
<?php |
<?php |
| 2 |
// $Id: $ |
// $Id: node_expire.nodeapi.inc,v 1.1 2009/01/26 23:56:49 brmassa Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 24 |
|
|
| 25 |
case 'prepare': |
case 'prepare': |
| 26 |
if (!isset($node->expire)) { |
if (!isset($node->expire)) { |
| 27 |
$node->expire = format_date(strtotime($ntypes), 'custom', NODE_EXPIRE_FORMAT); |
$node->expire = format_date(strtotime($ntypes['default']), 'custom', NODE_EXPIRE_FORMAT); |
| 28 |
} |
} |
| 29 |
break; |
break; |
| 30 |
|
|
| 36 |
elseif (strtotime($node->expire) <= time()) { |
elseif (strtotime($node->expire) <= time()) { |
| 37 |
form_set_error('expire_date', t("You can't expire a node in the past!")); |
form_set_error('expire_date', t("You can't expire a node in the past!")); |
| 38 |
} |
} |
| 39 |
|
elseif (strtotime($node->expire) > strtotime($ntypes['max'], $node->created)) { |
| 40 |
|
form_set_error('expire_date', t('It must expire before %date.', |
| 41 |
|
array('%date' => format_date(strtotime($ntypes['max']), 'custom', NODE_EXPIRE_FORMAT)))); |
| 42 |
|
} |
| 43 |
break; |
break; |
| 44 |
|
|
| 45 |
case 'update': |
case 'update': |
| 58 |
break; |
break; |
| 59 |
} |
} |
| 60 |
} |
} |
| 61 |
|
|
| 62 |
|
function _node_expire_form_alter_nodeform(&$ntypes, &$form, &$form_state, $form_id) { |
| 63 |
|
// Check if the Node Expire feature is enabled for the node type |
| 64 |
|
$node = isset($form['#node']) ? $form['#node'] : NULL; |
| 65 |
|
|
| 66 |
|
// Convert the timestamp into a human readable date |
| 67 |
|
if (is_numeric($node->expire)) { |
| 68 |
|
$node->expire = format_date($node->expire, 'custom', NODE_EXPIRE_FORMAT); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
if (user_access('edit node expire')) { |
| 72 |
|
$expire_field = array( |
| 73 |
|
'#title' => t('Expiration Date'), |
| 74 |
|
'#description' => t('Time date to consider the node expired. Format: %time.', |
| 75 |
|
array('%time' => format_date(time(), 'custom', NODE_EXPIRE_FORMAT))), |
| 76 |
|
'#type' => 'textfield', |
| 77 |
|
'#maxlength' => 25, |
| 78 |
|
'#default_value' => $node->expire, |
| 79 |
|
); |
| 80 |
|
|
| 81 |
|
// In case jQuery UI module is enabled, use it to |
| 82 |
|
// get the DatePicker widget. |
| 83 |
|
if (module_exists('jquery_ui')) { |
| 84 |
|
jquery_ui_add('ui.datepicker'); |
| 85 |
|
drupal_add_js(drupal_get_path('module', 'node_expire') .'/node_expire.js'); |
| 86 |
|
$min = empty($node->created) ? time() : $node->created; |
| 87 |
|
$min = array( |
| 88 |
|
format_date($min, 'custom', 'Y'), |
| 89 |
|
format_date($min, 'custom', 'm'), |
| 90 |
|
format_date($min, 'custom', 'd'), |
| 91 |
|
); |
| 92 |
|
if (!empty($ntypes['max'])) { |
| 93 |
|
$max = strtotime($ntypes['max'], (empty($node->created) ? time() : $node->created)); |
| 94 |
|
$max = array( |
| 95 |
|
format_date($max, 'custom', 'Y'), |
| 96 |
|
format_date($max, 'custom', 'm'), |
| 97 |
|
format_date($max, 'custom', 'd'), |
| 98 |
|
); |
| 99 |
|
} |
| 100 |
|
else { |
| 101 |
|
$max = NULL; |
| 102 |
|
} |
| 103 |
|
drupal_add_js(array( |
| 104 |
|
'dateFormat' => NODE_EXPIRE_FORMAT_JS, |
| 105 |
|
'minDate' => $min, |
| 106 |
|
'maxDate' => $max, |
| 107 |
|
), 'setting'); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
else { |
| 111 |
|
$expire_field = array( |
| 112 |
|
'#type' => 'value', |
| 113 |
|
'#value' => $node->expire |
| 114 |
|
); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
// Put the expire field into 'Publising options' if possible |
| 118 |
|
if (user_access('administer nodes')) { |
| 119 |
|
$form['options']['expire'] = &$expire_field; |
| 120 |
|
} |
| 121 |
|
else { |
| 122 |
|
$form['expire'] = &$expire_field; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
if (isset($node->expired)) { |
| 126 |
|
$form['node_expire'] = array( |
| 127 |
|
'#type' => 'value', |
| 128 |
|
'#value' => TRUE, |
| 129 |
|
); |
| 130 |
|
} |
| 131 |
|
} |