PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/e107_core/shortcodes/single/imagepreview.php

https://github.com/CasperGemini/e107
PHP | 60 lines | 51 code | 7 blank | 2 comment | 13 complexity | 043b3242504f7eab01c8a67590e4e383 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // $Id$
  3. function imagepreview_shortcode($parm)
  4. {
  5. list($name, $width, $height, $nothumb) = explode("|",$parm, 4);
  6. $name = rawurldecode(varset($name));//avoid warnings
  7. if(varset($width))
  8. {
  9. $width = intval($width);
  10. }
  11. else $width = 0;
  12. if(varset($height))
  13. {
  14. $height = intval($height);
  15. }
  16. else $height = 0;
  17. // array support
  18. if(strpos($name, '[')) //can't be first string
  19. {
  20. $matches = array();
  21. $search = $name;
  22. $tmp = explode('[', $name, 2);
  23. $name = $tmp[0]; unset($tmp);
  24. $path = '';
  25. if(isset($_POST[$name]) && is_array($_POST[$name]) && preg_match_all('#\[([\w]*)\]#', $search, $matches, PREG_PATTERN_ORDER))
  26. {
  27. $posted = $_POST[$name];
  28. foreach ($matches[1] as $varname)
  29. {
  30. if(!isset($posted[$varname]))
  31. {
  32. break;
  33. }
  34. $posted = $posted[$varname];
  35. }
  36. }
  37. if($posted && is_string($posted))
  38. $path = e107::getParser()->replaceConstants($posted, 'full');
  39. }
  40. else $path = (varset($_POST[$name])/* && deftrue('e_AJAX_REQUEST')*/) ? e107::getParser()->replaceConstants($_POST[$name], 'full') : '';
  41. $hide = '';
  42. if(!$path)
  43. {
  44. $path = '#';
  45. $thpath = e_IMAGE_ABS."generic/blank.gif";
  46. $hide = ' style="display: none;"';
  47. }
  48. else
  49. {
  50. $thpath = !varset($nothumb) ? e107::getParser()->thumbUrl($path, 'w='.$width.'h='.$height, true) : $path;
  51. }
  52. return "<a href='{$path}' rel='external shadowbox' class='e-image-preview'{$hide}><img src='{$thpath}' alt=\"\" class='image-selector' /></a>";
  53. }