Skip to content
Snippets Groups Projects
Commit bbca6b48 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #52418 by Zen: fapi conversion + bug fixes.

parent 6d9e5084
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -247,6 +247,9 @@ tr.odd .form-item, tr.even .form-item { ...@@ -247,6 +247,9 @@ tr.odd .form-item, tr.even .form-item {
.book-navigation .page-next { .book-navigation .page-next {
text-align: left; text-align: left;
} }
.archive {
margin: 1em 0 1em 0;
}
.calendar .row-week td a { .calendar .row-week td a {
display: block; display: block;
} }
......
...@@ -27,26 +27,52 @@ function archive_help($section) { ...@@ -27,26 +27,52 @@ function archive_help($section) {
} }
} }
/**
* Implementation of hook_menu().
*/
function archive_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'archive',
'title' => t('archives'),
'access' => user_access('access content'),
'callback' => 'archive_page',
'type' => MENU_SUGGESTED_ITEM);
}
return $items;
}
/**
* Implementation of hook_block().
*
* Generates a calendar for the current month, with links to the archives
* for each day.
*/
function archive_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
}
}
/** /**
* Generates a monthly calendar, for display in the archive block. * Generates a monthly calendar, for display in the archive block.
*/ */
function archive_calendar($original = 0) { function archive_calendar() {
global $user; global $user;
$edit = $_POST['edit'];
// Extract today's date: // Extract today's date:
$start_of_today = mktime(0, 0, 0, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone; $start_of_today = mktime(0, 0, 0, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone;
$end_of_today = mktime(23, 59, 59, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone; $end_of_today = mktime(23, 59, 59, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone;
// Extract the requested date: // Extract the requested date:
if ($edit['year'] && $edit['month'] && $edit['day']) { if (arg(0) == 'archive' && arg(3)) {
$year = $edit['year'];
$month = $edit['month'];
$day = $edit['day'];
$requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone;
}
else if (arg(0) == 'archive' && arg(3)) {
$year = arg(1); $year = arg(1);
$month = arg(2); $month = arg(2);
$day = arg(3); $day = arg(3);
...@@ -188,87 +214,78 @@ function archive_calendar($original = 0) { ...@@ -188,87 +214,78 @@ function archive_calendar($original = 0) {
return $output; return $output;
} }
/**
* Implementation of hook_block().
*
* Generates a calendar for the current month, with links to the archives
* for each day.
*/
function archive_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
}
}
/**
* Implementation of hook_menu().
*/
function archive_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'archive', 'title' => t('archives'),
'access' => user_access('access content'),
'callback' => 'archive_page',
'type' => MENU_SUGGESTED_ITEM);
}
return $items;
}
/** /**
* Menu callback; lists all nodes posted on a given date. * Menu callback; lists all nodes posted on a given date.
*/ */
function archive_page($year = 0, $month = 0, $day = 0) { function archive_page($year = 0, $month = 0, $day = 0) {
global $user; global $user;
$op = $_POST['op'];
$edit = $_POST['edit'];
if ($op == t('Show')) {
$year = $edit['year'];
$month = $edit['month'];
$day = $edit['day'];
}
$date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone; $date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone;
$date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone; $date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone;
// Prepare the values of the form fields. // Display form.
$years = drupal_map_assoc(range(2000, 2010)); $output = archive_browse_form($year, $month, $day);
$months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'));
$days = drupal_map_assoc(range(0, 31));
$form['year'] = array('#type' => 'select', '#default_value' => ($year ? $year : date('Y')), '#options' => $years);
$form['month'] = array('#type' => 'select', '#default_value' => ($month ? $month : date('m')), '#options' => $months);
$form['day'] = array('#type' => 'select', '#default_value' => ($day ? $day : date('d')), '#options' => $days);
$form['show'] = array('#type' => 'submit', '#value' => t('Show'));
$output = drupal_get_form('archive_dates', $form);
if ($year && $month && $day) { if ($year && $month && $day) {
// Fetch nodes for the selected date, if one was specified. // Fetch nodes for the selected date, if one was specified.
$sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created'; $sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created';
$sql = db_rewrite_sql($sql); $sql = db_rewrite_sql($sql);
$result = db_query_range($sql, $date, $date_end, 0, 20); $result = db_query_range($sql, $date, $date_end, 0, 20);
if (db_num_rows($result) > 0) {
while ($nid = db_fetch_object($result)) { while ($nid = db_fetch_object($result)) {
$output .= node_view(node_load($nid->nid), 1); $output .= node_view(node_load($nid->nid), 1);
}
} }
else {
$output .= theme('box', t('No posts found.'), '');
}
}
else {
$output .= theme('box', t('No posts found.'), '');
} }
return $output; return $output;
} }
/**
* Generate a form that retrieves archives for a certain date.
*/
function archive_browse_form($year, $month, $day) {
// Prepare the values of the form fields.
$years = drupal_map_assoc(range(2000, 2010));
$months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'));
$days = drupal_map_assoc(range(1, 31));
$form['year'] = array('#type' => 'select',
'#default_value' => ($year ? $year : date('Y')),
'#options' => $years,
);
$form['month'] = array('#type' => 'select',
'#default_value' => ($month ? $month : date('m')),
'#options' => $months,
);
$form['day'] = array('#type' => 'select',
'#default_value' => ($day ? $day : date('d')),
'#options' => $days,
);
$form['show'] = array('#type' => 'submit',
'#value' => t('Show'),
);
return drupal_get_form('archive_browse_form', $form);
}
/**
* Process archive browse form submission.
*/
function archive_browse_form_submit($form_id, $form_values) {
return('archive/'. $form_values['year'] .'/'. $form_values['month'] .'/'. $form_values['day']);
}
/** /**
* Form theme function; displays the archive date navigation form inline. * Form theme function; displays the archive date navigation form inline.
*/ */
function theme_archive_dates($form) { function theme_archive_browse_form($form) {
$output = '<div class="container-inline">' . form_render($form) . '</div>'; $output = '<div class="container-inline archive">' . form_render($form) . '</div>';
return $output; return $output;
} }
...@@ -27,26 +27,52 @@ function archive_help($section) { ...@@ -27,26 +27,52 @@ function archive_help($section) {
} }
} }
/**
* Implementation of hook_menu().
*/
function archive_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'archive',
'title' => t('archives'),
'access' => user_access('access content'),
'callback' => 'archive_page',
'type' => MENU_SUGGESTED_ITEM);
}
return $items;
}
/**
* Implementation of hook_block().
*
* Generates a calendar for the current month, with links to the archives
* for each day.
*/
function archive_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
}
}
/** /**
* Generates a monthly calendar, for display in the archive block. * Generates a monthly calendar, for display in the archive block.
*/ */
function archive_calendar($original = 0) { function archive_calendar() {
global $user; global $user;
$edit = $_POST['edit'];
// Extract today's date: // Extract today's date:
$start_of_today = mktime(0, 0, 0, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone; $start_of_today = mktime(0, 0, 0, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone;
$end_of_today = mktime(23, 59, 59, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone; $end_of_today = mktime(23, 59, 59, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone;
// Extract the requested date: // Extract the requested date:
if ($edit['year'] && $edit['month'] && $edit['day']) { if (arg(0) == 'archive' && arg(3)) {
$year = $edit['year'];
$month = $edit['month'];
$day = $edit['day'];
$requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone;
}
else if (arg(0) == 'archive' && arg(3)) {
$year = arg(1); $year = arg(1);
$month = arg(2); $month = arg(2);
$day = arg(3); $day = arg(3);
...@@ -188,87 +214,78 @@ function archive_calendar($original = 0) { ...@@ -188,87 +214,78 @@ function archive_calendar($original = 0) {
return $output; return $output;
} }
/**
* Implementation of hook_block().
*
* Generates a calendar for the current month, with links to the archives
* for each day.
*/
function archive_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
}
}
/**
* Implementation of hook_menu().
*/
function archive_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'archive', 'title' => t('archives'),
'access' => user_access('access content'),
'callback' => 'archive_page',
'type' => MENU_SUGGESTED_ITEM);
}
return $items;
}
/** /**
* Menu callback; lists all nodes posted on a given date. * Menu callback; lists all nodes posted on a given date.
*/ */
function archive_page($year = 0, $month = 0, $day = 0) { function archive_page($year = 0, $month = 0, $day = 0) {
global $user; global $user;
$op = $_POST['op'];
$edit = $_POST['edit'];
if ($op == t('Show')) {
$year = $edit['year'];
$month = $edit['month'];
$day = $edit['day'];
}
$date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone; $date = mktime(0, 0, 0, $month, $day, $year) - $user->timezone;
$date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone; $date_end = mktime(0, 0, 0, $month, $day + 1, $year) - $user->timezone;
// Prepare the values of the form fields. // Display form.
$years = drupal_map_assoc(range(2000, 2010)); $output = archive_browse_form($year, $month, $day);
$months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'));
$days = drupal_map_assoc(range(0, 31));
$form['year'] = array('#type' => 'select', '#default_value' => ($year ? $year : date('Y')), '#options' => $years);
$form['month'] = array('#type' => 'select', '#default_value' => ($month ? $month : date('m')), '#options' => $months);
$form['day'] = array('#type' => 'select', '#default_value' => ($day ? $day : date('d')), '#options' => $days);
$form['show'] = array('#type' => 'submit', '#value' => t('Show'));
$output = drupal_get_form('archive_dates', $form);
if ($year && $month && $day) { if ($year && $month && $day) {
// Fetch nodes for the selected date, if one was specified. // Fetch nodes for the selected date, if one was specified.
$sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created'; $sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created';
$sql = db_rewrite_sql($sql); $sql = db_rewrite_sql($sql);
$result = db_query_range($sql, $date, $date_end, 0, 20); $result = db_query_range($sql, $date, $date_end, 0, 20);
if (db_num_rows($result) > 0) {
while ($nid = db_fetch_object($result)) { while ($nid = db_fetch_object($result)) {
$output .= node_view(node_load($nid->nid), 1); $output .= node_view(node_load($nid->nid), 1);
}
} }
else {
$output .= theme('box', t('No posts found.'), '');
}
}
else {
$output .= theme('box', t('No posts found.'), '');
} }
return $output; return $output;
} }
/**
* Generate a form that retrieves archives for a certain date.
*/
function archive_browse_form($year, $month, $day) {
// Prepare the values of the form fields.
$years = drupal_map_assoc(range(2000, 2010));
$months = array(1 => t('January'), 2 => t('February'), 3 => t('March'), 4 => t('April'), 5 => t('May'), 6 => t('June'), 7 => t('July'), 8 => t('August'), 9 => t('September'), 10 => t('October'), 11 => t('November'), 12 => t('December'));
$days = drupal_map_assoc(range(1, 31));
$form['year'] = array('#type' => 'select',
'#default_value' => ($year ? $year : date('Y')),
'#options' => $years,
);
$form['month'] = array('#type' => 'select',
'#default_value' => ($month ? $month : date('m')),
'#options' => $months,
);
$form['day'] = array('#type' => 'select',
'#default_value' => ($day ? $day : date('d')),
'#options' => $days,
);
$form['show'] = array('#type' => 'submit',
'#value' => t('Show'),
);
return drupal_get_form('archive_browse_form', $form);
}
/**
* Process archive browse form submission.
*/
function archive_browse_form_submit($form_id, $form_values) {
return('archive/'. $form_values['year'] .'/'. $form_values['month'] .'/'. $form_values['day']);
}
/** /**
* Form theme function; displays the archive date navigation form inline. * Form theme function; displays the archive date navigation form inline.
*/ */
function theme_archive_dates($form) { function theme_archive_browse_form($form) {
$output = '<div class="container-inline">' . form_render($form) . '</div>'; $output = '<div class="container-inline archive">' . form_render($form) . '</div>';
return $output; return $output;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment