node.pre.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // get the body field
  31. $body = $vars['content']['body']['#items'][0]['value'];
  32. // get the frist image only
  33. preg_match('/<img[^src]+src="([^"]+)"[^>]+>/i', $body, $matches);
  34. // get the source path of the image
  35. $img_src = preg_replace('/^\/?sites\/default\/files\//', '', $matches[1]);
  36. // generate the uri of styled image
  37. $img_uri = image_style_url("card-full", $img_src);
  38. // generate the styled image file
  39. image_style_create_derivative("card-full", $img_src, $img_uri);
  40. // theme the new image tag
  41. $img = theme('image', array('path'=>$img_uri));
  42. // link the image to the node
  43. $img = l($img, "node/".$node->nid, array("html"=>true));
  44. // replace the body with this new styled image
  45. $vars['content']['body'][0]['#markup'] = $img;
  46. }