function cly_ad_image($identity) { $position = pdo_fetch("SELECT * FROM " . tablename('ad_position') . " WHERE identity=:identity", array('identity' => $identity)); $adList = pdo_fetchall("SELECT * FROM " . tablename('ad') . " WHERE position_id=:position_id AND type=1 AND (end_time=0 or UNIX_TIMESTAMP()<end_time) ORDER BY `order`,id", array('position_id' => $position['id'])); $html = "<style>{$position['css']}</style>"; foreach ($adList as $ad) { if ($ad['enable'] == 1 && !empty($ad['image_url'])) { $imageUrl = cly_image($ad['image_url']); $html .= <<<EOT <div class="{$identity}"> <a href="{$ad['link_url']}" target="_blank"> <img src="{$imageUrl}"/> </a> </div> EOT; } else { $html .= <<<EOT <div class="{$identity}"> <span>广告招商</span> </div> EOT; } } return $html; }
function cache_build_ad($identity = null) { if (is_string($identity)) { $position = pdo_fetch("SELECT * FROM " . tablename('ad_position') . " WHERE identity=:identity", array('identity' => $identity)); $adList = pdo_fetchall("SELECT * FROM " . tablename('ad') . " WHERE position_id=:position_id ORDER BY `order`,id", array('position_id' => $position['id'])); $html = "<style>{$position['css']}</style>"; foreach ($adList as $ad) { if ($ad['enable'] == 0 || $ad['time'] != 0 && $ad['time'] > time() || empty($ad['image_url']) && empty($ad['code'])) { $html .= <<<EOT <div class="{$identity}"> <div class="adEmpty" style="text-align:center"> 广告招商 </div> </div> EOT; } else { if ($ad['type'] == 1) { $imageUrl = cly_image($ad['image_url']); $html .= <<<EOT <div class="{$identity}"> <a href="{$ad['link_url']}" target="_blank"> <img src="{$imageUrl}"/> </a> </div> EOT; } elseif ($ad['type'] == 2) { $html .= <<<EOT <div class="{$identity}"> {$ad['code']} </div> EOT; } } cache_write($identity, $html); } } elseif (is_array($identity)) { foreach ($identity as $value) { cache_build_ad($value); } } elseif (is_null($identity)) { $data = pdo_fetchall("SELECT `identity` FROM " . tablename('ad_position')); foreach ($data as $row) { $identitys[] = $row['identity']; } cache_build_ad(array_values($identitys)); } }