function.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * CMS公共方法
  4. *
  5. * 公共方法
  6. *
  7. */
  8. defined('InShopNC') or exit('Access Invalid!');
  9. function getRefUrl() {
  10. return urlencode('http://'.$_SERVER['HTTP_HOST'].request_uri());
  11. }
  12. function getLoadingImage() {
  13. return CMS_TEMPLATES_URL.DS.'images/loading.gif';
  14. }
  15. /**
  16. * 画报图片列表
  17. */
  18. function getPictureImageUrl($picture_id) {
  19. return CMS_SITE_URL.DS.'index.php?act=picture&op=picture_detail_image&picture_id='.$picture_id;
  20. }
  21. /**
  22. * 获取商品URL
  23. */
  24. function getGoodsUrl($goods_id) {
  25. return SHOP_SITE_URL.DS.'index.php?act=goods&goods_id='.$goods_id;
  26. }
  27. /**
  28. * 返回图片居中显示的样式字符串
  29. *
  30. * @param
  31. * $image_width 图片宽度
  32. * $image_height 图片高度
  33. * $box_width 目标图片尺寸宽度
  34. * $box_height 目标图片尺寸高度
  35. *
  36. * @return string 图片居中显示style字符串
  37. *
  38. */
  39. function getMiddleImgStyleString($image_width, $image_height, $box_width, $box_height) {
  40. $image_style = array();
  41. $image_style['width'] = $box_width;
  42. $image_style['height'] = $box_height;
  43. $image_style['left'] = 0;
  44. $image_style['top'] = 0;
  45. if( ($image_width - $box_width) > ($image_height - $box_height) ) {
  46. if($image_width > $box_width) {
  47. $image_style['width'] = $box_height / $image_height * $image_width;
  48. $image_style['left'] = ($box_width - $image_style['width']) / 2;
  49. }
  50. } else {
  51. if($image_height > $box_height) {
  52. $image_style['height'] = $box_width / $image_width * $image_height;
  53. $image_style['top'] = ($box_height - $image_style['height']) / 2;
  54. }
  55. }
  56. $style_string = 'style="';
  57. $style_string .= 'height: ' . $image_style['height'] . 'px;';
  58. $style_string .= ' width: ' . $image_style['width'] . 'px;';
  59. $style_string .= ' left: ' . $image_style['left'] . 'px;';
  60. $style_string .= 'top: ' . $image_style['top'] . 'px;';
  61. $style_string .= '"';
  62. return $style_string;
  63. }