Dstaglib.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\common\taglib;
  3. use think\template\TagLib;
  4. class Dstaglib extends TagLib{
  5. /**
  6. * 定义标签列表
  7. */
  8. protected $tags = [
  9. 'adv' => ['attr' => 'limit,order,where,item', 'close' => 1],
  10. ];
  11. public function tagAdv($tag, $content) {
  12. $order = !empty($tag['order']) ? $tag['order'] : ''; //排序
  13. $limit = !empty($tag['limit']) ? $tag['limit'] : '1';
  14. $where = !empty($tag['where']) ? $tag['where'] : ''; //查询条件
  15. $item = !empty($tag['item']) ? $tag['item'] : 'item'; // 返回的变量item
  16. $key = !empty($tag['key']) ? $tag['key'] : 'key'; // 返回的变量key
  17. $ap_id = !empty($tag['ap_id']) ? $tag['ap_id'] : '0'; // 返回的变量key
  18. $str = '<?php ';
  19. $str .= '$ap_id =' . $ap_id . ';';
  20. $str .= '$ad_position = db("advposition")->cache(3600)->column("ap_id,ap_name,ap_width,ap_height","ap_id");';
  21. $str .= '$result = db("adv")->where("ap_id=$ap_id and adv_enabled = 1")->order("adv_order desc")->cache(36000)->limit("' . $limit . '")->select();';
  22. $str .= '
  23. if(!in_array($ap_id,array_keys($ad_position)) && $ap_id)
  24. {
  25. db("advposition")->insert(array(
  26. "ap_id"=>$ap_id,
  27. "ap_name"=>request()->module()."/".request()->controller()."/".request()->action()."页面自动增加广告位 $ap_id ",
  28. ));
  29. $ad_position[$ap_id]=array();
  30. \think\Cache::clear();
  31. }
  32. $c = ' . $limit . '- count($result); // 如果要求数量 和实际数量不一样 并且编辑模式
  33. if($c > 0 && input("get.edit_ad"))
  34. {
  35. for($i = 0; $i < $c; $i++) // 还没有添加广告的时候
  36. {
  37. $result[] = array(
  38. "adv_id" => 0,
  39. "adv_code" => "/public/images/not_adv.jpg",
  40. "adv_link" => ADMIN_SITE_URL."/Adv/adv_add/ap_id/$ap_id.html",
  41. "adv_title" =>"暂无广告图片",
  42. "not_adv" => 1,
  43. "adv_target" => "_self",
  44. "ap_id" =>$ap_id,
  45. );
  46. }
  47. }
  48. foreach($result as $' . $key . '=>$' . $item . '):
  49. $'.$item. '["position"] = $ad_position[$' . $item . '["ap_id"]];
  50. $'.$item. '["adv_link"] = HOME_SITE_URL."/Advclick/Advclick/adv_id/".$' . $item . '["adv_id"].".html";
  51. $'.$item. '["adv_target"] = "_blank";
  52. if(input("get.edit_ad") && !isset($' . $item . '["not_adv"]) )
  53. {
  54. $' . $item . '["style"] = "filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5"; // 广告半透明的样式
  55. $' . $item . '["adv_link"] = ADMIN_SITE_URL."/Adv/adv_edit/adv_id/".$' . $item . '[\'adv_id\'].".html";
  56. $' . $item . '["adv_title"] = $ad_position[$' . $item . '["ap_id"]]["ap_name"]."===".$' . $item . '["adv_title"];
  57. $' . $item . '["adv_target"] = "_self";
  58. $' . $item . '["adv_style"] = "filter:alpha(opacity=30); -moz-opacity:0.3; -khtml-opacity: 0.3; opacity: 0.3";
  59. }
  60. ?>';
  61. $str .= $content;
  62. $str .= '<?php endforeach; ?>';
  63. if (!empty($str)) {
  64. return $str;
  65. }
  66. return;
  67. }
  68. }