template.theme-overrides.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. function perfarttimeline_links__locale_block(&$vars) {
  3. // global $language;
  4. // foreach ($vars['links'] as $lang => $link) {
  5. // $vars['links'][$lang]['title'] = $lang;
  6. // // if($lang == $language->language)
  7. // // unset($vars['link'][$lang]);
  8. // }
  9. $content = theme_links($vars);
  10. return $content;
  11. }
  12. /**
  13. * Returns HTML for an image using a specific image style.
  14. *
  15. * @param $variables
  16. * An associative array containing:
  17. * - style_name: The name of the style to be used to alter the original image.
  18. * - path: The path of the image file relative to the Drupal files directory.
  19. * This function does not work with images outside the files directory nor
  20. * with remotely hosted images. This should be in a format such as
  21. * 'images/image.jpg', or using a stream wrapper such as
  22. * 'public://images/image.jpg'.
  23. * - width: The width of the source image (if known).
  24. * - height: The height of the source image (if known).
  25. * - alt: The alternative text for text-based browsers.
  26. * - title: The title text is displayed when the image is hovered in some
  27. * popular browsers.
  28. * - attributes: Associative array of attributes to be placed in the img tag.
  29. *
  30. * @ingroup themeable
  31. */
  32. function perfarttimeline_image_style($vars) {
  33. // dpm($vars);
  34. $original_path = $vars['path'];
  35. _perfarttimeline_getImageStyleDimensions($vars);
  36. $figure = '<figure style="width:'.$vars['width'].'px;height:'.$vars['height'].'px;">';
  37. $styles = array('grid_small', 'grid_medium', 'grid_large');
  38. if(in_array($vars['style_name'], $styles)){
  39. foreach ($styles as $style) {
  40. $vars['attributes']['class'] = 'image '.$style;
  41. if($style == $vars['style_name']){
  42. // $vars['path'] = image_style_url($vars['style_name'], $original_path);
  43. // $vars['path'] = image_style_path($vars['style_name'], $original_path);
  44. $url = image_style_url($style, $original_path);
  45. $url = parse_url($url);
  46. $vars['path'] = $url['path'];
  47. $figure .= theme('image', $vars);
  48. }else{
  49. $hidden_vars = array_merge(array(), $vars);
  50. $hidden_vars['style_name'] = $style;
  51. _perfarttimeline_getImageStyleDimensions($hidden_vars);
  52. // $hidden_vars['attributes']['path'] = image_style_url($style, $original_path);
  53. // $hidden_vars['attributes']['path'] = image_style_path($style, $original_path);
  54. $url = image_style_url($style, $original_path);
  55. $url = parse_url($url);
  56. $hidden_vars['attributes']['path'] = $url['path'];
  57. $hidden_vars['path'] = "";
  58. $figure .= theme('image', $hidden_vars);
  59. }
  60. }
  61. }else{
  62. $vars['attributes']['class'] = 'image '.$vars['style_name'];
  63. // $vars['path'] = image_style_url($vars['style_name'], $original_path);
  64. // $style_path = image_style_path($vars['style_name'], $original_path);
  65. // $url = file_create_url($style_path);
  66. $url = image_style_url($vars['style_name'], $original_path);
  67. $url = parse_url($url);
  68. $vars['path'] = $url['path'];
  69. $figure .= theme('image', $vars);
  70. }
  71. #gif
  72. $gifvariables = array_merge(array(), $vars);
  73. $gifvariables['path'] = '/'. drupal_get_path("theme", "perfarttimeline") .'/images/blank.gif';
  74. $gifvariables['attributes']['class'] = 'blank';
  75. $gifvariables['title'] = $gifvariables['alt'] = '';
  76. $figure .= theme('image', $gifvariables);
  77. #figcaption
  78. $figure .= '<figcaption>'.$vars['title'].'</figcaption>';
  79. $figure .= '</figure>';
  80. return $figure;
  81. }
  82. function _perfarttimeline_getImageStyleDimensions(&$vars){
  83. $dimensions = array(
  84. 'width' => $vars['width'],
  85. 'height' => $vars['height'],
  86. );
  87. image_style_transform_dimensions($vars['style_name'], $dimensions);
  88. $vars['width'] = $dimensions['width'];
  89. $vars['height'] = $dimensions['height'];
  90. }
  91. function perfarttimeline_menu_tree__main_menu($variables) {
  92. // dsm($variables);
  93. global $language;
  94. preg_match_all('/<li[^>]+><a[^>]+>/', $variables['tree'], $links);
  95. // dsm($links, 'links');
  96. if(isset($links[0])){
  97. foreach ($links[0] as $link) {
  98. preg_match('/href="([^"]+)"/', $link, $path);
  99. $normal_path = drupal_get_normal_path( preg_replace('/^\/fr\/|\/en\//', '', $path[1]) );
  100. // dsm($normal_path, 'normal_path');
  101. preg_match('/node\/([0-9]+)/', $normal_path, $matches);
  102. // dsm($matches2, 'matches2');
  103. if(isset($matches[1])){
  104. $node = node_load($matches[1]);
  105. if(in_array($node->type, array('temoignage', 'biographie', 'document_video'))){
  106. $prenom = field_get_items('node', $node, 'field_prenom', $language->language);
  107. $nom = field_get_items('node', $node, 'field_nom', $language->language);
  108. // dsm($nom, 'nom');
  109. // dsm($prenom, 'prenom');
  110. $new_link = preg_replace('/(<li[^>]+)>/', '${1} prenom="'.$prenom[0]['value'].'" nom="'.$nom[0]['value'].'">', $link);
  111. // dsm($new_link, 'new_link');
  112. $variables['tree'] = str_replace($link, $new_link, $variables['tree']);
  113. }
  114. }
  115. }
  116. }
  117. return '<ul class="menu main-menu">' . $variables['tree'] . '</ul>';
  118. }