template.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /**
  3. * Override or insert variables into the html template.
  4. *
  5. * @param $vars
  6. * An array of variables to pass to the theme template.
  7. */
  8. function popsu_preprocess_html(&$vars) {
  9. //drupal_add_css('/sites/default/themes/popsu/css/css3/css3.css', array('group' => CSS_THEME + 1,'every_page' =>TRUE));
  10. //drupal_add_css('/sites/default/themes/popsu/css/css3/css3_graphics.css', array('group' => CSS_THEME + 2,'every_page' =>TRUE));
  11. // give <body> tag a unique class depending on PATHs
  12. $path_alias = strtolower(drupal_clean_css_identifier(drupal_get_path_alias($_GET['q'])));
  13. if ($path_alias == 'node') {
  14. $vars['classes_array'][] = '';
  15. }
  16. else {
  17. $vars['classes_array'][] = 'path-'. $path_alias;
  18. }
  19. // Add to the array of body classes
  20. // layout classes
  21. $vars['classes_array'][] = 'layout-'. (!empty($vars['page']['sidebar_first']) ? 'first-main' : 'main') . (!empty($vars['page']['sidebar_second']) ? '-second' : '');
  22. }
  23. /**
  24. * Override or insert variables into the page template.
  25. *
  26. * @param $vars
  27. * An array of variables to pass to the theme template.
  28. */
  29. function popsu_preprocess_page(&$vars) {
  30. // Render manager menu tree from main-menu
  31. //$menu_tree = menu_tree('menu-manager-menu');
  32. //$vars['menu_manager_menu_tree'] = render($menu_tree);
  33. $menu_tree = menu_tree_all_data('menu-manager-menu');
  34. $vars['menu_manager_menu_tree'] = menu_tree_output($menu_tree);
  35. }
  36. /**
  37. * Override or insert variables into the node templates.
  38. *
  39. * @param $vars
  40. * An array of variables to pass to the theme template.
  41. */
  42. function popsu_preprocess_node(&$vars) {
  43. $vars['classes_array'][] = $vars['zebra'];
  44. if ($vars['view_mode'] == 'full') {
  45. $vars['classes_array'][] = 'node-full';
  46. }
  47. // Add node-type-page template suggestion
  48. if ($vars['page']) {
  49. $vars['theme_hook_suggestions'][] = 'node__'. $vars['node']->type .'_page';
  50. $vars['theme_hook_suggestions'][] = 'node__'. $vars['node']->type .'-'. $vars['node']->nid .'_page';
  51. }
  52. else {
  53. $vars['theme_hook_suggestions'][] = 'node__'. $vars['node']->type .'_teaser';
  54. $vars['theme_hook_suggestions'][] = 'node__'. $vars['node']->nid;
  55. }
  56. }
  57. /**
  58. * Preprocess variables for region.tpl.php
  59. *
  60. * Prepare the values passed to the theme_region function to be passed into a
  61. * pluggable template engine. Uses the region name to generate a template file
  62. * suggestions. If none are found, the default region.tpl.php is used.
  63. *
  64. * @see region.tpl.php
  65. */
  66. function popsu_preprocess_region(&$vars) {
  67. // Sidebar region template suggestion.
  68. if (strpos($vars['region'], 'sidebar_') === 0) {
  69. $vars['theme_hook_suggestions'][] = 'region__sidebar';
  70. $vars['theme_hook_suggestions'][] = 'region__' . $vars['region'];
  71. }
  72. }
  73. /**
  74. * Override or insert variables into the block templates.
  75. *
  76. * @param $vars
  77. * An array of variables to pass to the theme template.
  78. */
  79. function popsu_preprocess_block(&$vars) {
  80. $block = $vars['block'];
  81. // First/last block position
  82. $vars['position'] = ($vars['block_id'] == 1) ? 'first' : '';
  83. if ($vars['block_id'] == count(block_list($block->region))) {
  84. $vars['position'] = ($vars['position']) ? '' : 'last';
  85. }
  86. }
  87. /**
  88. * Override or insert variables into the comment templates.
  89. *
  90. * @param $vars
  91. * An array of variables to pass to the theme template.
  92. */
  93. function popsu_preprocess_comment(&$vars) {
  94. // Add odd/even classes to comments classes_array
  95. static $comment_odd = TRUE;
  96. $vars['classes_array'][] = $comment_odd ? 'odd' : 'even';
  97. $comment_odd = !$comment_odd;
  98. }
  99. function popsu_form_element($variables) {
  100. $element = &$variables['element'];
  101. // This is also used in the installer, pre-database setup.
  102. $t = get_t();
  103. // This function is invoked as theme wrapper, but the rendered form element
  104. // may not necessarily have been processed by form_builder().
  105. $element += array(
  106. '#title_display' => 'before',
  107. );
  108. // Add element #id for #type 'item'.
  109. if (isset($element['#markup']) && !empty($element['#id'])) {
  110. $attributes['id'] = $element['#id'];
  111. }
  112. // Add element's #type and #name as class to aid with JS/CSS selectors.
  113. $attributes['class'] = array('form-item');
  114. $error = form_get_error($element);
  115. if (!empty($error) ) {
  116. $attributes['class'][] = 'error';
  117. }
  118. if (!empty($element['#type'])) {
  119. $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
  120. }
  121. if (!empty($element['#name'])) {
  122. $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
  123. }
  124. // Add a class for disabled elements to facilitate cross-browser styling.
  125. if (!empty($element['#attributes']['disabled'])) {
  126. $attributes['class'][] = 'form-disabled';
  127. }
  128. $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
  129. // If #title is not set, we don't display any label or required marker.
  130. if (!isset($element['#title'])) {
  131. $element['#title_display'] = 'none';
  132. }
  133. $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
  134. $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
  135. switch ($element['#title_display']) {
  136. case 'before':
  137. case 'invisible':
  138. $output .= ' ' . theme('form_element_label', $variables);
  139. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  140. break;
  141. case 'after':
  142. $output .= ' ' . $prefix . $element['#children'] . $suffix;
  143. $output .= ' ' . theme('form_element_label', $variables) . "\n";
  144. break;
  145. case 'none':
  146. case 'attribute':
  147. // Output no label and no required marker, only the children.
  148. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  149. break;
  150. }
  151. if (!empty($element['#description'])) {
  152. $output .= '<div class="description">' . $element['#description'] . "</div>\n";
  153. } else if( !empty($error) ) {
  154. $output .= '<div class="description">' . $error . '</div><!--/.description-->';
  155. }
  156. $output .= "</div>\n";
  157. return $output;
  158. }
  159. function popsu_pager($variables) {
  160. $tags = $variables['tags'];
  161. $element = $variables['element'];
  162. $parameters = $variables['parameters'];
  163. $quantity = $variables['quantity'];
  164. global $pager_page_array, $pager_total;
  165. // Calculate various markers within this pager piece:
  166. // Middle is used to "center" pages around the current page.
  167. $pager_middle = ceil($quantity / 2);
  168. // current is the page we are currently paged to
  169. $pager_current = $pager_page_array[$element] + 1;
  170. // first is the first page listed by this pager piece (re quantity)
  171. $pager_first = $pager_current - $pager_middle + 1;
  172. // last is the last page listed by this pager piece (re quantity)
  173. $pager_last = $pager_current + $quantity - $pager_middle;
  174. // max is the maximum page number
  175. $pager_max = $pager_total[$element];
  176. // End of marker calculations.
  177. // Prepare for generation loop.
  178. $i = $pager_first;
  179. if ($pager_last > $pager_max) {
  180. // Adjust "center" if at end of query.
  181. $i = $i + ($pager_max - $pager_last);
  182. $pager_last = $pager_max;
  183. }
  184. if ($i <= 0) {
  185. // Adjust "center" if at start of query.
  186. $pager_last = $pager_last + (1 - $i);
  187. $i = 1;
  188. }
  189. // End of generation loop preparation.
  190. $li_first = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters));
  191. $li_previous = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('‹ previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
  192. $li_next = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next ›')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
  193. $li_last = theme('pager_last', array('text' => (isset($tags[4]) ? $tags[4] : t('last »')), 'element' => $element, 'parameters' => $parameters));
  194. if ($pager_total[$element] > 1) {
  195. if ($li_first) {
  196. $items[] = array(
  197. 'class' => array('pager-first'),
  198. 'data' => $li_first,
  199. );
  200. }
  201. if ($li_previous) {
  202. $items[] = array(
  203. 'class' => array('pager-previous'),
  204. 'data' => $li_previous,
  205. );
  206. }
  207. // When there is more than one page, create the pager list.
  208. if ($i != $pager_max) {
  209. if ($i > 1) {
  210. $items[] = array(
  211. 'class' => array('pager-ellipsis'),
  212. 'data' => '<a onclick="return false;" href="#">…</a>',
  213. );
  214. }
  215. // Now generate the actual pager piece.
  216. for (; $i <= $pager_last && $i <= $pager_max; $i++) {
  217. if ($i < $pager_current) {
  218. $items[] = array(
  219. 'class' => array('pager-item'),
  220. 'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),
  221. );
  222. }
  223. if ($i == $pager_current) {
  224. $items[] = array(
  225. 'class' => array('pager-current active'),
  226. 'data' => "<a href=\"#\">$i</a>",
  227. );
  228. }
  229. if ($i > $pager_current) {
  230. $items[] = array(
  231. 'class' => array('pager-item'),
  232. 'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),
  233. );
  234. }
  235. }
  236. if ($i < $pager_max) {
  237. $items[] = array(
  238. 'class' => array('pager-ellipsis disabled'),
  239. 'data' => '<a onclick="return false;" href="#">…</a>',
  240. );
  241. }
  242. }
  243. // End generation.
  244. if ($li_next) {
  245. $items[] = array(
  246. 'class' => array('pager-next'),
  247. 'data' => $li_next,
  248. );
  249. }
  250. if ($li_last) {
  251. $items[] = array(
  252. 'class' => array('pager-last'),
  253. 'data' => $li_last,
  254. );
  255. }
  256. return '<div class="pagination pagination-centered">'.theme('item_list', array(
  257. 'items' => $items,
  258. )).'</div>';
  259. }
  260. }
  261. function popsu_menu_link($v) {
  262. $atts = &$v['element']['#attributes']; //alias
  263. if( isset($atts['class'])
  264. && in_array('active-trail',$atts['class']) ) {
  265. $atts['class'][] = 'active';
  266. }
  267. /* rcuny - patch pour nid dans les menus */
  268. $nid = $v['element']['#href'];
  269. if ($nid != "") {
  270. $nid = substr($nid, 5);
  271. if (is_numeric($nid)) {
  272. $atts['class'][] = 'nid-' . $nid;
  273. }
  274. }
  275. return theme_menu_link($v);
  276. }
  277. /**
  278. * Implementation of CKEditor default height (http://groups.drupal.org/node/170324)
  279. */
  280. function popsu_wysiwyg_editor_settings_alter(&$settings, $context) {
  281. if($context['profile']->editor == 'ckeditor') {
  282. $settings['height'] = 300;
  283. }
  284. }