node.pre.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // dsm($vars);
  3. $node = $vars['node'];
  4. // $classes = array();
  5. $vars['classes_array'][] = 'node-'.$node->nid;
  6. // $vars['classes_array'][] = 'node type-'.$node->type;
  7. $vars['classes_array'][] = 'vm-'.$vars['view_mode'];
  8. // $classes[] = 'node-' . $vars['type'] . '-' . $vars['view_mode'];
  9. if($vars['sticky'])
  10. $vars['classes_array'][] = "sticky";
  11. if (!$vars['status'])
  12. $vars['classes_array'][] = "unpublished";
  13. if (isset($vars['flags']))
  14. $vars['classes_array'][] = "flaged";
  15. // $vars['classes_array'][] = $hook.' '.$hook.'-'.$vars['zebra'];
  16. if (isset($vars['workflow']))
  17. $vars['classes_array'][] = "workflow-".$vars['workflow'];
  18. $vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
  19. $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
  20. if($vars['view_mode'] == 'bookmark')
  21. unset($vars['content']['links']);
  22. // dsm($vars);
  23. if($vars['type'] == 'didactique'){
  24. // dsm($node, 'node');
  25. if(!empty($node->field_emvideo))
  26. $vars['classes_array'][] = "emvideo";
  27. }
  28. // for HOME V2 : remove all table and other html, remains only the picture, from simplenews daily materio
  29. if ($vars['type'] == 'simplenews' && $vars['view_mode'] == 'teaser') {
  30. // dsm($vars, "vars");
  31. // dsm($vars['simplenews']->name);
  32. // get the body field
  33. $body = $vars['content']['body']['#items'][0]['value'];
  34. // get the frist image only
  35. // preg_match_all('/<img[^src]+src="([^"]+)"[^>]+\/>/i', $body, $matches);
  36. preg_match_all('/<img([\w\W]+?)\/>/i', $body, $imgs);
  37. // dsm($imgs);
  38. foreach ($imgs[1] as $key => $value) {
  39. preg_match('/src="([^"]+)"/i', $value, $matches);
  40. // dsm($matches[1]);
  41. if (strpos('cale.jpg', $matches[1]) === false) {
  42. // get the source path of the image
  43. $img_src = preg_replace('/^\/?sites\/default\/files\//', '', $matches[1]);
  44. break;
  45. }
  46. }
  47. // dsm($img_src);
  48. // generate the uri of styled image
  49. $img_uri = image_style_url("card-full", $img_src);
  50. // generate the styled image file
  51. image_style_create_derivative("card-full", $img_src, $img_uri);
  52. // theme the new image tag
  53. $img = theme('image', array('path'=>$img_uri));
  54. // link the image to the node
  55. $img = l($img, "node/".$node->nid, array("html"=>true));
  56. // replace the body with this new styled image
  57. $vars['content']['body'][0]['#markup'] = $img;
  58. }