Files
orico-official-website-old/app/index/controller/Ad.php
2024-10-29 14:04:59 +08:00

187 lines
8.2 KiB
PHP
Executable File

<?php
namespace app\index\controller;
use think\Lang;
use think\Loader;
use think\Config;
use app\common\controller\BaseController;
class Ad extends BaseController {
private $country_code = 'ZH';
public function tags($tags = '', $num = 1) {
if ($tags) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'adzh-' . md5($tags);
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($htmlbody)) {
$list = Loader::model('Ad')->getList(['stat' => 0, 'tags' => $tags, 'country_code' => $this->country_code], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
if (empty($list)) {
$this->cacheTag('adTagZh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--403-->\");\r\n-->\r\n");
exit;
}
$htmlbody = '';
$expire = 3600;
foreach ($list as $row) {
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$exp = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$exp = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$exp = $row['endtime'] - $ntime;
}
}
$expire = $exp > 0 && $exp < $expire ? $exp : $expire;
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$htmlbody .= "<!--\r\ndocument.write(\"{$adbody}\");\r\n-->\r\n";
//print_r($htmlbody);exit;
}
$this->cacheTag('adTagZh')->set($cacheTag, $htmlbody, $expire);
}
echo $htmlbody;
exit;
}
exit(' Error! ');
}
public function tagsli($tags = '', $num = 1) {
if ($tags) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'adzh-' . md5($tags);
$htmlbody = $nocache == false ? '' : $this->cacheGet($cacheTag);
if (empty($htmlbody)) {
$list = Loader::model('Ad')->getList(['stat' => 0, 'tags' => $tags, 'typeid' => 5, 'country_code' => $this->country_code], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
if (empty($list)) {
$this->cacheTag('adTagZh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--405-->\");\r\n-->\r\n");
exit;
}
$htmlbody = '';
$expire = 3600;
foreach ($list as $k => $row) {
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$exp = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$exp = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$exp = $row['endtime'] - $ntime;
}
}
$expire = $exp > 0 && $exp < $expire ? $exp : $expire;
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$htmlbody .= "<!--\r\ndocument.write(\"<li class=\\\"li" . ($k + 2) . "\\\">{$adbody}</li>\");\r\n-->\r\n";
}
$this->cacheTag('adTagZh')->set($cacheTag, $htmlbody, $expire);
}
echo $htmlbody;
exit;
}
exit(' Error! ');
}
public function index($id = 0) {
if ($id > 0) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'adzh-' . $id;
$adbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($adbody)) {
$row = Loader::model('Ad')->where(['stat' => ['eq', 0], 'id' => $id, 'country_code' => $this->country_code])->find();
if (empty($row)) {
$this->cacheTag('adTagZh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--406-->\");\r\n-->\r\n");
exit;
}
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$expire = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$expire = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$expire = $row['endtime'] - $ntime;
}
}
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$adbody = "<!--\r\ndocument.write(\"{$adbody}\");\r\n-->\r\n";
$this->cacheTag('adTagZh')->set($cacheTag, $adbody, $expire);
}
echo $adbody;
exit;
}
exit(' Error! ');
}
public function cat($id = '', $num = 1) {
if ($id) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'adzh-' . $id;
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($htmlbody)) {
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'typeid' => $id, 'country_code'], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
if (empty($list)) {
$this->cacheTag('adTagZh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--407-->\");\r\n-->\r\n");
exit;
}
$htmlbody = '';
$expire = 3600;
foreach ($list as $row) {
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$exp = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$exp = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$exp = $row['endtime'] - $ntime;
}
}
$expire = $exp > 0 && $exp < $expire ? $exp : $expire;
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$htmlbody .= "<!--\r\ndocument.write(\"{$adbody}\");\r\n-->\r\n";
}
$this->cacheTag('adTagZh')->set($cacheTag, $htmlbody, $expire);
}
echo $htmlbody;
exit;
}
exit(' Error! ');
}
public function previewjs($id) {
$id = intval($id);
if ($id > 0) {
echo '<script src="' . url('index/ad/index', ['id' => $id]) . '?nocache=1" language="javascript"></script>';
}
exit();
}
}