adv.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. defined('InShopNC') or exit('Access Invalid!');
  3. /**
  4. * 取广告内容
  5. *
  6. * @param unknown_type $ap_id
  7. * @param unknown_type $type html,js,array
  8. */
  9. function advshow($ap_id, $type = 'js'){
  10. if($ap_id < 1)return;
  11. $time = time();
  12. $ap_info = Model('adv')->getApById($ap_id);
  13. if (!$ap_info)
  14. return;
  15. $list = $ap_info['adv_list'];unset($ap_info['adv_list']);
  16. extract($ap_info);
  17. if($is_use !== '1'){
  18. return ;
  19. }
  20. $adv_list = array();
  21. $adv_info = array();//异步调用的数组格式
  22. foreach ((array)$list as $k=>$v){
  23. if($v['adv_start_date'] < $time && $v['adv_end_date'] > $time && $v['is_allow'] == '1'){
  24. $adv_list[] = $v;
  25. }
  26. }
  27. if(empty($adv_list)){
  28. if($ap_class == '1'){//文字广告
  29. $content .= "<a href=''>";
  30. $content .= $default_content;
  31. $content .= "</a>";
  32. }else{
  33. $width = $ap_width;
  34. $height = $ap_height;
  35. $content .= "<a href='' title='".$ap_name."'>";
  36. $content .= "<img style='width:{$width}px;height:{$height}px' border='0' src='";
  37. $content .= UPLOAD_SITE_URL."/".ATTACH_ADV."/".$default_content;
  38. $content .= "' alt=''/>";
  39. $content .= "</a>";
  40. $adv_info['adv_title'] = $ap_name;
  41. $adv_info['adv_img'] = UPLOAD_SITE_URL."/".ATTACH_ADV."/".$default_content;
  42. $adv_info['adv_url'] = '';
  43. }
  44. }else {
  45. $select = 0;
  46. if($ap_display == '1'){//多广告展示
  47. $select = array_rand($adv_list);
  48. }
  49. $adv_select = $adv_list[$select];
  50. extract($adv_select);
  51. //图片广告
  52. if($ap_class == '0'){
  53. $width = $ap_width;
  54. $height = $ap_height;
  55. $pic_content = unserialize($adv_content);
  56. $pic = $pic_content['adv_pic'];
  57. $url = $pic_content['adv_pic_url'];
  58. $content .= "<a href='http://".$pic_content['adv_pic_url']."' target='_blank' title='".$adv_title."'>";
  59. $content .= "<img style='width:{$width}px;height:{$height}px' border='0' src='";
  60. $content .= UPLOAD_SITE_URL."/".ATTACH_ADV."/".$pic;
  61. $content .= "' alt='".$adv_title."'/>";
  62. $content .= "</a>";
  63. $adv_info['adv_title'] = $adv_title;
  64. $adv_info['adv_img'] = UPLOAD_SITE_URL."/".ATTACH_ADV."/".$pic;
  65. $adv_info['adv_url'] = 'http://'.$pic_content['adv_pic_url'];
  66. }
  67. //文字广告
  68. if($ap_class == '1'){
  69. $word_content = unserialize($adv_content);
  70. $word = $word_content['adv_word'];
  71. $url = $word_content['adv_word_url'];
  72. $content .= "<a href='http://".$pic_content['adv_word_url']."' target='_blank'>";
  73. $content .= $word;
  74. $content .= "</a>";
  75. }
  76. //Flash广告
  77. if($ap_class == '3'){
  78. $width = $ap_width;
  79. $height = $ap_height;
  80. $flash_content = unserialize($adv_content);
  81. $flash = $flash_content['flash_swf'];
  82. $url = $flash_content['flash_url'];
  83. $content .= "<a href='http://".$url."' target='_blank'><button style='width:".$width."px; height:".$height."px; border:none; padding:0; background:none;' disabled><object id='FlashID' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='".$width."' height='".$height."'>";
  84. $content .= "<param name='movie' value='";
  85. $content .= UPLOAD_SITE_URL."/".ATTACH_ADV."/".$flash;
  86. $content .= "' /><param name='quality' value='high' /><param name='wmode' value='opaque' /><param name='swfversion' value='9.0.45.0' /><!-- 此 param 标签提示使用 Flash Player 6.0 r65 和更高版本的用户下载最新版本的 Flash Player。如果您不想让用户看到该提示,请将其删除。 --><param name='expressinstall' value='";
  87. $content .= RESOURCE_SITE_URL."/js/expressInstall.swf'/><!-- 下一个对象标签用于非 IE 浏览器。所以使用 IECC 将其从 IE 隐藏。 --><!--[if !IE]>--><object type='application/x-shockwave-flash' data='";
  88. $content .= UPLOAD_SITE_URL."/".ATTACH_ADV."/".$flash;
  89. $content .= "' width='".$width."' height='".$height."'><!--<![endif]--><param name='quality' value='high' /><param name='wmode' value='opaque' /><param name='swfversion' value='9.0.45.0' /><param name='expressinstall' value='";
  90. $content .= RESOURCE_SITE_URL."/js/expressInstall.swf'/><!-- 浏览器将以下替代内容显示给使用 Flash Player 6.0 和更低版本的用户。 --><div><h4>此页面上的内容需要较新版本的 Adobe Flash Player。</h4><p><a href='http://www.adobe.com/go/getflashplayer'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='获取 Adobe Flash Player' width='112' height='33' /></a></p></div><!--[if !IE]>--></object><!--<![endif]--></object></button></a>";
  91. }
  92. }
  93. if ($type == 'array' && $ap_class == '0'){
  94. return $adv_info;
  95. }
  96. if ($type == 'js'){
  97. $content = "document.write(\"".$content."\");";
  98. }
  99. return $content;
  100. }