init
This commit is contained in:
185
app/usmobile/controller/Ad.php
Executable file
185
app/usmobile/controller/Ad.php
Executable file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace app\usmobile\controller;
|
||||
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Config;
|
||||
use app\common\controller\BaseController;
|
||||
|
||||
class Ad extends BaseController {
|
||||
|
||||
public function tags($tags = '', $num = 1) {
|
||||
if ($tags) {
|
||||
$nocache = $this->request->param('nocache', 0);
|
||||
$cacheTag = 'ad-' . md5($tags);
|
||||
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
|
||||
if (empty($htmlbody)) {
|
||||
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'tags' => $tags], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
|
||||
if (empty($list)) {
|
||||
$this->cacheTag('adTag')->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('adTag')->set($cacheTag, $htmlbody, $expire);
|
||||
}
|
||||
echo $htmlbody;
|
||||
exit;
|
||||
}
|
||||
exit(' Error! ');
|
||||
}
|
||||
|
||||
public function tagsli($tags = '', $num = 1) {
|
||||
if ($tags) {
|
||||
$nocache = $this->request->param('nocache', 0);
|
||||
$cacheTag = 'ad-' . md5($tags);
|
||||
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
|
||||
if (empty($htmlbody)) {
|
||||
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'tags' => $tags], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
|
||||
if (empty($list)) {
|
||||
$this->cacheTag('adTag')->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";
|
||||
//print_r($htmlbody);exit;
|
||||
}
|
||||
$this->cacheTag('adTag')->set($cacheTag, $htmlbody, $expire);
|
||||
}
|
||||
echo $htmlbody;
|
||||
exit;
|
||||
}
|
||||
exit(' Error! ');
|
||||
}
|
||||
|
||||
public function index($id = 0) {
|
||||
if ($id > 0) {
|
||||
$nocache = $this->request->param('nocache', 0);
|
||||
$cacheTag = 'ad-' . $id;
|
||||
$adbody = $nocache ? '' : $this->cacheGet($cacheTag);
|
||||
if (empty($adbody)) {
|
||||
$row = Loader::model('Ad')->where(['stat' => ['eq', 0], 'id' => $id])->find();
|
||||
if (empty($row)) {
|
||||
$this->cacheTag('adTag')->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('adTag')->set($cacheTag, $adbody, $expire);
|
||||
}
|
||||
echo $adbody;
|
||||
exit;
|
||||
}
|
||||
exit(' Error! ');
|
||||
}
|
||||
|
||||
public function cat($id = '', $num = 1) {
|
||||
if ($id) {
|
||||
$nocache = $this->request->param('nocache', 0);
|
||||
$cacheTag = 'ad-' . $id;
|
||||
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
|
||||
if (empty($htmlbody)) {
|
||||
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'typeid' => $id], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
|
||||
if (empty($list)) {
|
||||
$this->cacheTag('adTag')->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('adTag')->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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user