1.在数据库里面执行sql语句
CREATE TABLE `typecho_t` ( `id` int(11) UNSIGNED NOT NULL, `name` char(20) NOT NULL, `txt` varchar(255) NOT NULL, `qq` char(10) NOT NULL, `time` varchar(30) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `typecho_t` ADD PRIMARY KEY (`id`); ALTER TABLE `typecho_t` MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=208; COMMIT;
上面的是作者原版,我自用下面这段SQL语句,自行测试。
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; CREATE TABLE `typecho_t` ( `id` int(11) UNSIGNED NOT NULL, `name` char(20) NOT NULL, `txt` varchar(255) NOT NULL, `qq` char(10) NOT NULL, `time` varchar(30) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `typecho_t` ADD PRIMARY KEY (`id`); ALTER TABLE `typecho_t` MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=171; COMMIT;
2.新建uc-page.php
<?php /** * uc page * * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; $this->need('header.php'); ?> <style> .page-content table{ margin-bottom: 15px; width: 100%; min-width: 100%; min-height: 110px; } .page-content table tr td{ position: relative; } .tra{ width: 76px; max-width: 76px; min-width: 76px; } .page-content table *{ border: none; } .tra .divimg{ display: block; width: 50px; height: 50px; margin: 0; position: absolute; top: 5px; bottom: 0; left: 10px; right: 0; border: 0; border-radius: inherit; background-size: cover; background-repeat: no-repeat; background-position: 50% 50%; border-radius: 50%; } .conn::after{ content: ''; display: block; clear: both; } .conn img{ display: block; } .page-a:before{ font-family: none; content: ''; } .page-a{ padding: 3px 5px; } .page-content img{ max-height: 200px; } </style> <!--毒鸡汤--> <?php $file = 'soul.json'; $soul = json_decode(file_get_contents($file), true); $count = count($soul); $rand = rand(0, $count); $content = $soul[$rand]['content']; if (isset($_GET['type'])) { header('Content-type:application/json'); exit(json_encode($soul[$rand])); } ?> 来碗毒鸡汤:<font color="green"><p class="content"><?php echo $content;?></p></font> <div class="layout"> <div class="page"> <article class="page-body"> <div class="page-content"> <?php foreach (Sel($_GET["page"]) as $mdi): ?> <table border="1"> <tr> <td class="tra" rowspan="2"><div class="divimg" style="background-image:url(<?php echo qqimg($mdi['qq']); ?>)"></div></td> <td><font color="red"><?php echo $mdi['name']; ?></font><img src="https://1.342600.xyz/ico/ym.png"> </td> <td style="float:right;"><font color="blue"><?php echo $mdi['time']; ?></font></td> </tr> <tr> <td class="conn" colspan="2"><?php echo TiHuan($mdi['txt']); ?></td> </tr> </table> <?php endforeach; ?> <?php sspages(); ?> </div> </article> </div> </div> <?php $this->need('footer.php'); ?> <HR style="FILTER: alpha(opacity=0,finishopacity=100,style=1)" width="80%" color=#987cb9 SIZE=3>
3.插入function.php数据
//机器人插入说说数据处理 function AddT($name1,$txt1,$qq1){ $key = "random"; $txt = trim($txt1); //清理空格 $txt = strip_tags($txt); //过滤html标签 $txt = htmlspecialchars($txt); //将字符内容转化为html实体 $txt = addslashes($txt); $txt = urldecode($txt); $name = trim($name1); //清理空格 $name = strip_tags($name); //过滤html标签 $name = htmlspecialchars($name); //将字符内容转化为html实体 $name = addslashes($name); $name = urldecode($name); $qq = trim($qq1); //清理空格 $qq = strip_tags($qq); //过滤html标签 $qq = htmlspecialchars($qq); //将字符内容转化为html实体 $qq = addslashes($qq); $qq = urldecode($qq); if($key==$_GET["key"]){//判断key是否存在或正确 if(preg_match('/[1-9]([0-9]{5,11})/', $qq, $matches)){//判断qq号是否规范 if(mb_strlen($txt,'UTF8')<255){//字符串必须小于255位 if(strstr($txt, '$')||strstr($txt, '<')||strstr($txt, '>')||strstr($txt, '\"')||strstr($txt, '\'')||strstr($txt, '#')){ return -1;//存在特殊字符 }else{ $db = Typecho_Db::get(); $rs = $db->insert('table.t')->rows(array('id' => null, 'name' => $name , 'txt' => $txt , 'qq' => $qq , 'time' => date("Y/m/d") )); return $db->query($rs);//成功 } }else{ return -2;//长度值大于255 } }else{ return -3;//qq错误 } }else{ return -4;//key不正确 } } //获取qq头像并加密qq号 function qqimg($qq){ $geturl = 'http://ptlogin2.qq.com/getface?&imgtype=1&uin='.$qq; $qquser = file_get_contents($geturl); $str1 = explode('sdk&k=', $qquser); $str2 = explode('&s=', $str1[1]); $k = $str2[0]; $url = 'https://q1.qlogo.cn/g?b=qq&k='.$k.'&s=100'; return $url; } //字符替换把*img和img*替换成<img src=''> function TiHuan($img){ if(strstr($img,"img")) { $pagelink=str_ireplace('*img' , "<img src='" , $img); $pagelink=str_ireplace('img*' , "'>",$pagelink); return $pagelink; }else{ return $img; } } //查询说说数量-->分页用 function coun(){ $db = Typecho_Db::get(); $po=$db->select('table.t.qq')->from ('table.t'); $pom = $db->fetchAll($po); $num = count($pom); $shu = 0; for ($x=0; $x<$num; $x++) { $shu+=1; } if($shu%10==0){ return $shu/10; }else{ return floor($shu/10+1); } } //说说分页 function sspages(){ for($i=0;$i<coun();$i++){ echo '<a class="page-a" href="https://1.342600.xyz/uc?page='.($i+1).'">'.($i+1).'</a>'; } } //说说展示 function Sel($pagess){ $pa = trim($pagess); //清理空格 $pa = strip_tags($pa); //过滤html标签 $pa = htmlspecialchars($pa); //将字符内容转化为html实体 $pa = addslashes($pa);//给每个双引号转义 $db = Typecho_Db::get(); $query= $db->select()->from('table.t')->page($pa,10)->order('id',Typecho_Db::SORT_DESC); return $db->fetchAll($query); } /****************说说结束*****************/
4.新建fun.php
<?php /** * INSERTJSON * * @package custom */ header("Content-Type:text/html;charset=UTF-8"); if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php if(isset($_GET["name"])&&isset($_GET["txt"])&&isset($_GET["qq"])){ $r = AddT($_GET["name"],$_GET["txt"],$_GET["qq"]); $te; if($r==-1){ $te = "I don't know that.~~~"; }else if($r==-2){ $te = "It's too long~~~"; }else if($r==-3){ $te = "QQ error"; }else if($r==-4){ $te = "Key error"; }else{ $this->response->throwJson(array("ret" => $r , "msg" => $te )); } }else{ echo '如果你来到了这个页面,那说明我们很有缘, 既然这么有缘,那么我就坦白告诉你,这里除了这段话什么都没有'; } ?>