theme.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /**
  3. * @file
  4. * Theme files for Date Pager.
  5. */
  6. /**
  7. * Jump in and move the pager.
  8. */
  9. function date_views_preprocess_views_view(&$vars) {
  10. $view = $vars['view'];
  11. if (!empty($view->date_info) && !empty($view->date_info->date_pager_position)) {
  12. switch ($view->date_info->date_pager_position) {
  13. case 'top':
  14. $vars['header'] .= $vars['pager'];
  15. $vars['pager'] = '';
  16. break;
  17. case 'both':
  18. $vars['header'] .= $vars['pager'];
  19. break;
  20. default:
  21. // Already on the bottom.
  22. }
  23. }
  24. }
  25. /**
  26. * Preprocess function for Date pager template.
  27. */
  28. function template_preprocess_date_views_pager(&$vars) {
  29. ctools_add_css('date_views', 'date_views');
  30. $plugin = $vars['plugin'];
  31. $input = $vars['input'];
  32. $view = $plugin->view;
  33. $vars['nav_title'] = '';
  34. $vars['next_url'] = '';
  35. $vars['prev_url'] = '';
  36. if (empty($view->date_info) || empty($view->date_info->min_date)) {
  37. return;
  38. }
  39. $date_info = $view->date_info;
  40. // Make sure we have some sort of granularity.
  41. $granularity = !empty($date_info->granularity) ? $date_info->granularity : 'month';
  42. $pos = $date_info->date_arg_pos;
  43. if (!empty($input)) {
  44. $id = $plugin->options['date_id'];
  45. if (array_key_exists($id, $input) && !empty($input[$id])) {
  46. $view->args[$pos] = $input[$id];
  47. }
  48. }
  49. $next_args = $view->args;
  50. $prev_args = $view->args;
  51. $min_date = $date_info->min_date;
  52. $max_date = $date_info->max_date;
  53. // Set up the pager link format. Setting the block identifier
  54. // will force pager style links.
  55. if ((isset($date_info->date_pager_format) && $date_info->date_pager_format != 'clean') || !empty($date_info->mini)) {
  56. if (empty($date_info->block_identifier)) {
  57. $date_info->block_identifier = $date_info->pager_id;
  58. }
  59. }
  60. if (empty($date_info->hide_nav)) {
  61. $prev_date = clone($min_date);
  62. date_modify($prev_date, '-1 ' . $granularity);
  63. $next_date = clone($min_date);
  64. date_modify($next_date, '+1 ' . $granularity);
  65. $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d');
  66. switch ($granularity) {
  67. case 'week':
  68. $next_week = date_week(date_format($next_date, 'Y-m-d'));
  69. $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
  70. $next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
  71. $prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
  72. break;
  73. default:
  74. $next_arg = date_format($next_date, $format[$granularity]);
  75. $prev_arg = date_format($prev_date, $format[$granularity]);
  76. }
  77. $next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
  78. $prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
  79. $next_args[$pos] = $next_arg;
  80. $prev_args[$pos] = $prev_arg;
  81. $vars['next_url'] = date_pager_url($view, NULL, $next_arg);
  82. $vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
  83. $vars['next_options'] = $vars['prev_options'] = array();
  84. }
  85. else {
  86. $next_path = '';
  87. $prev_path = '';
  88. $vars['next_url'] = '';
  89. $vars['prev_url'] = '';
  90. $vars['next_options'] = $vars['prev_options'] = array();
  91. }
  92. // Check whether navigation links would point to
  93. // a date outside the allowed range.
  94. if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
  95. $vars['next_url'] = '';
  96. }
  97. if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
  98. $vars['prev_url'] = '';
  99. }
  100. $vars['prev_options'] += array('attributes' => array());
  101. $vars['next_options'] += array('attributes' => array());
  102. $prev_title = '';
  103. $next_title = '';
  104. // Build next/prev link titles.
  105. switch ($granularity) {
  106. case 'year':
  107. $prev_title = t('Navigate to previous year');
  108. $next_title = t('Navigate to next year');
  109. break;
  110. case 'month':
  111. $prev_title = t('Navigate to previous month');
  112. $next_title = t('Navigate to next month');
  113. break;
  114. case 'week':
  115. $prev_title = t('Navigate to previous week');
  116. $next_title = t('Navigate to next week');
  117. break;
  118. case 'day':
  119. $prev_title = t('Navigate to previous day');
  120. $next_title = t('Navigate to next day');
  121. break;
  122. }
  123. $vars['prev_options']['attributes'] += array('title' => $prev_title);
  124. $vars['next_options']['attributes'] += array('title' => $next_title);
  125. // Add nofollow for next/prev links.
  126. $vars['prev_options']['attributes'] += array('rel' => 'nofollow');
  127. $vars['next_options']['attributes'] += array('rel' => 'nofollow');
  128. // Need this so we can use '&laquo;' or images in the links.
  129. $vars['prev_options'] += array('html' => TRUE);
  130. $vars['next_options'] += array('html' => TRUE);
  131. $link = FALSE;
  132. // Month navigation titles are used as links in the block view.
  133. if (!empty($date_info->mini) && $granularity == 'month') {
  134. $link = TRUE;
  135. }
  136. $params = array(
  137. 'granularity' => $granularity,
  138. 'view' => $view,
  139. 'link' => $link,
  140. );
  141. $nav_title = theme('date_nav_title', $params);
  142. $vars['nav_title'] = $nav_title;
  143. $vars['mini'] = !empty($date_info->mini);
  144. }
  145. /**
  146. * Theme the calendar title
  147. */
  148. function theme_date_nav_title($params) {
  149. $granularity = $params['granularity'];
  150. $view = $params['view'];
  151. $date_info = $view->date_info;
  152. $link = !empty($params['link']) ? $params['link'] : FALSE;
  153. $format = !empty($params['format']) ? $params['format'] : NULL;
  154. $format_with_year = variable_get('date_views_' . $granularity . 'format_with_year', 'l, F j, Y');
  155. $format_without_year = variable_get('date_views_' . $granularity . 'format_without_year', 'l, F j');
  156. switch ($granularity) {
  157. case 'year':
  158. $title = $date_info->year;
  159. $date_arg = $date_info->year;
  160. break;
  161. case 'month':
  162. $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
  163. $title = date_format_date($date_info->min_date, 'custom', $format);
  164. $date_arg = $date_info->year . '-' . date_pad($date_info->month);
  165. break;
  166. case 'day':
  167. $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
  168. $title = date_format_date($date_info->min_date, 'custom', $format);
  169. $date_arg = $date_info->year . '-' . date_pad($date_info->month) . '-' . date_pad($date_info->day);
  170. break;
  171. case 'week':
  172. $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
  173. $title = t('Week of @date', array('@date' => date_format_date($date_info->min_date, 'custom', $format)));
  174. $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
  175. break;
  176. }
  177. if (!empty($date_info->mini) || $link) {
  178. // Month navigation titles are used as links in the mini view.
  179. $attributes = array('title' => t('View full page month'));
  180. $url = date_pager_url($view, $granularity, $date_arg, TRUE);
  181. return l($title, $url, array('attributes' => $attributes));
  182. }
  183. else {
  184. return $title;
  185. }
  186. }
  187. /**
  188. * Preprocessor for Date Views filter form.
  189. */
  190. function template_preprocess_date_views_filter_form(&$vars) {
  191. $form = $vars['form'];
  192. $vars['date'] = drupal_render($form['valuedate']);
  193. $vars['mindate'] = drupal_render($form['mindate']);
  194. $vars['maxdate'] = drupal_render($form['maxdate']);
  195. $vars['adjustment'] = drupal_render($form['valueadjustment']);
  196. $vars['minadjustment'] = drupal_render($form['minadjustment']);
  197. $vars['maxadjustment'] = drupal_render($form['maxadjustment']);
  198. $vars['description'] = drupal_render($form['description']) . drupal_render($form);
  199. }