theme.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 = $date_info->prev_date;
  62. $next_date = $date_info->next_date;
  63. $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d', 'hour' => 'Y-m-d\TH');
  64. if (!empty($prev_date)) {
  65. switch ($granularity) {
  66. case 'week':
  67. $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
  68. $prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
  69. break;
  70. default:
  71. $prev_arg = date_format($prev_date, $format[$granularity]);
  72. }
  73. $prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
  74. $prev_args[$pos] = $prev_arg;
  75. $vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
  76. }
  77. if (!empty($next_date)) {
  78. switch ($granularity) {
  79. case 'week':
  80. $next_week = date_week(date_format($next_date, 'Y-m-d'));
  81. $next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
  82. break;
  83. default:
  84. $next_arg = date_format($next_date, $format[$granularity]);
  85. }
  86. $next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
  87. $next_args[$pos] = $next_arg;
  88. $vars['next_url'] = date_pager_url($view, NULL, $next_arg);
  89. }
  90. $vars['next_options'] = $vars['prev_options'] = array();
  91. }
  92. else {
  93. $next_path = '';
  94. $prev_path = '';
  95. $vars['next_url'] = '';
  96. $vars['prev_url'] = '';
  97. $vars['next_options'] = $vars['prev_options'] = array();
  98. }
  99. // Check whether navigation links would point to
  100. // a date outside the allowed range.
  101. if (!empty($next_date) && !empty($vars['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
  102. $vars['next_url'] = '';
  103. }
  104. if (!empty($prev_date) && !empty($vars['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
  105. $vars['prev_url'] = '';
  106. }
  107. $vars['prev_options'] += array('attributes' => array());
  108. $vars['next_options'] += array('attributes' => array());
  109. $prev_title = '';
  110. $next_title = '';
  111. // Build next/prev link titles.
  112. switch ($granularity) {
  113. case 'year':
  114. $prev_title = t('Navigate to previous year');
  115. $next_title = t('Navigate to next year');
  116. break;
  117. case 'month':
  118. $prev_title = t('Navigate to previous month');
  119. $next_title = t('Navigate to next month');
  120. break;
  121. case 'week':
  122. $prev_title = t('Navigate to previous week');
  123. $next_title = t('Navigate to next week');
  124. break;
  125. case 'day':
  126. $prev_title = t('Navigate to previous day');
  127. $next_title = t('Navigate to next day');
  128. break;
  129. }
  130. $vars['prev_options']['attributes'] += array('title' => $prev_title);
  131. $vars['next_options']['attributes'] += array('title' => $next_title);
  132. // Add nofollow for next/prev links.
  133. $vars['prev_options']['attributes'] += array('rel' => 'nofollow');
  134. $vars['next_options']['attributes'] += array('rel' => 'nofollow');
  135. // Need this so we can use '&laquo;' or images in the links.
  136. $vars['prev_options'] += array('html' => TRUE);
  137. $vars['next_options'] += array('html' => TRUE);
  138. $link = FALSE;
  139. // Month navigation titles are used as links in the block view.
  140. if (!empty($date_info->mini) && $granularity == 'month') {
  141. $link = TRUE;
  142. }
  143. $params = array(
  144. 'granularity' => $granularity,
  145. 'view' => $view,
  146. 'link' => $link,
  147. );
  148. $nav_title = theme('date_nav_title', $params);
  149. $vars['nav_title'] = $nav_title;
  150. $vars['mini'] = !empty($date_info->mini);
  151. }
  152. /**
  153. * Theme the calendar title.
  154. */
  155. function theme_date_nav_title($params) {
  156. $title = '';
  157. $granularity = $params['granularity'];
  158. $view = $params['view'];
  159. $date_info = $view->date_info;
  160. $link = !empty($params['link']) ? $params['link'] : FALSE;
  161. $format = !empty($params['format']) ? $params['format'] : NULL;
  162. $format_with_year = variable_get('date_views_' . $granularity . '_format_with_year', 'l, F j, Y');
  163. $format_without_year = variable_get('date_views_' . $granularity . '_format_without_year', 'l, F j');
  164. switch ($granularity) {
  165. case 'year':
  166. $title = $date_info->year;
  167. $date_arg = $date_info->year;
  168. break;
  169. case 'month':
  170. $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
  171. $title = date_format_date($date_info->min_date, 'custom', $format);
  172. $date_arg = $date_info->year . '-' . date_pad($date_info->month);
  173. break;
  174. case 'day':
  175. $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
  176. $title = date_format_date($date_info->min_date, 'custom', $format);
  177. $date_arg = $date_info->year;
  178. $date_arg .= '-';
  179. $date_arg .= date_pad($date_info->month);
  180. $date_arg .= '-';
  181. $date_arg .= date_pad($date_info->day);
  182. break;
  183. case 'week':
  184. $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
  185. $title = t('Week of @date', array(
  186. '@date' => date_format_date($date_info->min_date, 'custom', $format),
  187. ));
  188. $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
  189. break;
  190. }
  191. if (!empty($date_info->mini) || $link) {
  192. // Month navigation titles are used as links in the mini view.
  193. $attributes = array('title' => t('View full page month'));
  194. $url = date_pager_url($view, $granularity, $date_arg, TRUE);
  195. return l($title, $url, array('attributes' => $attributes));
  196. }
  197. else {
  198. return $title;
  199. }
  200. }
  201. /**
  202. * Preprocessor for Date Views filter form.
  203. */
  204. function template_preprocess_date_views_filter_form(&$vars) {
  205. $form = $vars['form'];
  206. $vars['date'] = drupal_render($form['valuedate']);
  207. $vars['mindate'] = drupal_render($form['mindate']);
  208. $vars['maxdate'] = drupal_render($form['maxdate']);
  209. $vars['adjustment'] = drupal_render($form['valueadjustment']);
  210. $vars['minadjustment'] = drupal_render($form['minadjustment']);
  211. $vars['maxadjustment'] = drupal_render($form['maxadjustment']);
  212. $vars['description'] = drupal_render($form['description']) . drupal_render($form);
  213. }