189 lines
8.3 KiB
PHP
Executable File
189 lines
8.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\th\controller;
|
|
|
|
use think\Lang;
|
|
use think\Loader;
|
|
use think\Config;
|
|
use app\common\controller\BaseController;
|
|
|
|
class Ad extends BaseController {
|
|
private $country_code = 'TH';
|
|
public function tags($tags = '', $num = 1) {
|
|
if ($tags) {
|
|
$nocache = $this->request->param('nocache', 0);
|
|
$cacheTag = 'adth-' . 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('adTagTh')->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('adTagTh')->set($cacheTag, $htmlbody, $expire);
|
|
}
|
|
echo $htmlbody;
|
|
exit;
|
|
}
|
|
exit(' Error! ');
|
|
}
|
|
|
|
public function tagsli($tags = '', $num = 1) {
|
|
if ($tags) {
|
|
$nocache = $this->request->param('nocache', 0);
|
|
$cacheTag = 'adth-' . md5($tags);
|
|
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
|
|
|
|
if (empty($htmlbody)) {
|
|
$list = Loader::model('ad')->getList(['stat' => ['eq', 0], 'tags' => $tags, 'typeid' => 20, '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('adTagTh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--408-->\");\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";
|
|
//print_r($htmlbody);exit;
|
|
}
|
|
$this->cacheTag('adTagTh')->set($cacheTag, $htmlbody, $expire);
|
|
}
|
|
echo $htmlbody;
|
|
exit;
|
|
}
|
|
exit(' Error! ');
|
|
}
|
|
|
|
public function index($id = 0) {
|
|
if ($id > 0) {
|
|
$nocache = $this->request->param('nocache', 0);
|
|
$cacheTag = 'adth-' . $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('adTagTh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--405-->\");\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('adTagTh')->set($cacheTag, $adbody, $expire);
|
|
}
|
|
echo $adbody;
|
|
exit;
|
|
}
|
|
exit(' Error! ');
|
|
}
|
|
|
|
public function cat($id = '', $num = 1) {
|
|
if ($id) {
|
|
$nocache = $this->request->param('nocache', 0);
|
|
$cacheTag = 'adth-' . $id;
|
|
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
|
|
if (empty($htmlbody)) {
|
|
$list = Loader::model('ad')->getList(['stat' => ['eq', 0], 'typeid' => $id, '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('adTagTh')->set($cacheTag, "<!--\r\ndocument.write(\"<!--406-->\");\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('adTagTh')->set($cacheTag, $htmlbody, $expire);
|
|
}
|
|
echo $htmlbody;
|
|
exit;
|
|
}
|
|
exit(' Error! ');
|
|
}
|
|
|
|
public function previewjs($id) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
echo '<script src="' . url('th/ad/index', ['id' => $id]) . '?nocache=1" language="javascript"></script>';
|
|
}
|
|
exit();
|
|
}
|
|
|
|
}
|