Commit f1d3b72b authored by Liam Morland's avatar Liam Morland
Browse files

Refactor: Simplify regular expressions

parent 7e75e0f2
......@@ -271,7 +271,7 @@ function uw_ct_event_views_pre_render(&$view) {
// If we have the format YYYY-MM, change title.
// If we dont have that format it is just YYYY.
if (preg_match('/[0-9]{4}-[0-9]{1,2}/', $date)) {
if (preg_match('/\d{4}-\d{1,2}/', $date)) {
$display_date = date("F Y", strtotime($date));
$view->build_info['title'] = t('Events - @display_date', array('@display_date' => $display_date));
}
......@@ -305,10 +305,10 @@ function uw_ct_event_views_pre_view(&$view, &$display_id, &$args) {
$view->args[0] = $match[1] . '-1';
}
}
if (isset($path[2]) && (preg_match('/^(\d{4}-(?:[123456789]|1[012]))$/', $path[2], $match) || preg_match('/^(\d{4}-(?:0[123456789]|1[012]))$/', $path[2], $match))) {
if (isset($path[2]) && (preg_match('/^(\d{4}-(?:[1-9]|1[0-2]))$/', $path[2], $match) || preg_match('/^(\d{4}-(?:0[1-9]|1[0-2]))$/', $path[2], $match))) {
$view->args[0] = $match[1];
}
if (isset($path[2]) && preg_match('/^(\d{4}-(?:[123456789]|1[012]))-(?:[123456789]|[12]\d|3[01])$/', $path[2], $match)) {
if (isset($path[2]) && preg_match('/^(\d{4}-(?:[1-9]|1[0-2]))-(?:[1-9]|[12]\d|3[01])$/', $path[2], $match)) {
$view->args[0] = $match[1];
}
}
......@@ -352,7 +352,7 @@ function uw_ct_event_views_query_alter(&$view, &$query) {
}
}
else {
if (preg_match('/^(\d{4}-(?:[123456789]|1[012]))$/', $path[2], $match) || preg_match('/^(\d{4}-(?:0[123456789]|1[012]))$/', $path[2], $match)) {
if (preg_match('/^(\d{4}-(?:[1-9]|1[0-2]))$/', $path[2], $match) || preg_match('/^(\d{4}-(?:0[1-9]|1[0-2]))$/', $path[2], $match)) {
$archive_year_month = $match[0];
if (isset($archive_year_month) && $view->exposed_raw_input['date'] == $archive_year_month) {
unset($query->where[1]['conditions'][$key]);
......@@ -795,7 +795,7 @@ function uw_ct_event_init() {
// Redirect events/archive/$PATH[2],
// when $PATH[2] is NOT in a date format we would pass.
if ($path[0] == 'events' && isset($path[1]) && ($path[1] == 'archive') && isset($path[2])) {
if (!preg_match('/^\d{4}(?:-(?:[123456789]|1[012]))?$/', $path[2])) {
if (!preg_match('/^\d{4}(?:-(?:[1-9]|1[0-2]))?$/', $path[2])) {
drupal_set_message(t('Invalid event date URL. You have been redirected to the main "events" page.'), 'warning');
drupal_goto('events', array(), 301);
}
......@@ -821,13 +821,13 @@ function uw_ct_event_init() {
}
// Redirect events/calendar/NOTADATE.
if ($path[0] == 'events' && isset($path[1]) && $path[1] == 'calendar' && isset($path[2]) && !preg_match('/^[0-9]{4}-(0?[1-9]|1[0-2])$/', $path[2])) {
if ($path[0] == 'events' && isset($path[1]) && $path[1] == 'calendar' && isset($path[2]) && !preg_match('/^\d{4}-(0?[1-9]|1[0-2])$/', $path[2])) {
drupal_set_message(t('Invalid calendar URL. You have been redirected to the main "calendar" page.'), 'warning');
drupal_goto('events/calendar', array(), 301);
}
// Redirect events/day/NOTADATE.
if ($path[0] == 'events' && isset($path[1]) && $path[1] == 'day' && isset($path[2]) && !preg_match('/^[0-9]{4}-(0?[1-9]|1[0-2])(-[0-9]{1,2})$/', $path[2])) {
if ($path[0] == 'events' && isset($path[1]) && $path[1] == 'day' && isset($path[2]) && !preg_match('/^\d{4}-(0?[1-9]|1[0-2])(-\d{1,2})$/', $path[2])) {
drupal_set_message(t('Invalid day URL. You have been redirected to today\'s "day" page.'), 'warning');
drupal_goto('events/day', array(), 301);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment