template.custom-functions.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. function parseImagesOntext(&$text){
  3. // dsm($vars, 'vars');
  4. # parse images : left only the first in teaser, then replace all with image_cache
  5. preg_match_all('/<img[^>]+>/i',$text, $match_result);
  6. $allimgs = $match_result[0];
  7. // dsm($allimgs, '$allimgs');
  8. if(count($allimgs)){
  9. // if($vars['teaser']){
  10. // $first_img = array_shift($allimgs);
  11. // // dsm($first_img, '$first_img');
  12. // $img_link = l($first_img, 'node/'.$vars['nid'], array(
  13. // 'html' => true,
  14. // 'attributes' => array(
  15. // 'title' => htmlspecialchars($vars['title'])
  16. // ),
  17. // ));
  18. // // dsm($img_link, '$img_link');
  19. // $vars['content'] = str_replace($first_img, $img_link, $vars['content']);
  20. // if(count($allimgs)){
  21. // foreach ($allimgs as $key => $img)
  22. // $vars['content'] = str_replace($img, '', $vars['content']);
  23. // }
  24. // $allimgs = array($first_img);
  25. // $ic_preset = 'content_teaser';
  26. // }else{
  27. // $ic_preset = 'content_full';
  28. // }
  29. // $cached_img = array();
  30. $preset = 'content_full';
  31. foreach ($allimgs as $key => $img){
  32. preg_match('/src="([^"]*)"/', $img, $src);
  33. if(!preg_match('/^http:\/\//', $src[1])
  34. && !preg_match('/\.gif$/', $src[1])
  35. ){
  36. preg_match('/alt="([^"]*)"/', $img, $alt);
  37. preg_match('/title="([^"]*)"/', $img, $title);
  38. // dsm($src, '$src');
  39. // theme_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE, $absolute = TRUE)
  40. // $cached_img = theme('imagecache', $ic_preset, preg_replace('/^\//', '', $src[1]), $alt[1], $title[1]);
  41. // $image_infos['attributes']['class'] = 'image '.$preset;
  42. // $image_infos['path'] = image_style_url($preset, preg_replace('/^\//', '', $src[1]));
  43. // // dsm($image_infos['path'], 'path');
  44. // $cached_img = theme('image', $image_infos);
  45. $options['style_name'] = $preset;
  46. $options['path'] = preg_replace('/^\//', '', $src[1]);
  47. $options['alt'] = isset($alt[1]) ? $alt[1]:"";
  48. $options['title'] = isset($title[1]) ? $title[1]:"";
  49. $cached_img = theme('image_style', $options);
  50. // dsm($img, 'img');
  51. // dsm($cached_img, 'cached_img');
  52. $text = str_replace($img, $cached_img, $text);
  53. }
  54. }
  55. }
  56. }