2 Star 6 Fork 4

Byclemon/Pisces-Wetypecho

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Action.php 34.53 KB
一键复制 编辑 原始数据 按行查看 历史
Byclemon 提交于 2020-11-30 16:08 . weTypecho 1.5版本
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
<?php
header('Access-Control-Allow-Origin: *');
class WeTypecho_Action extends Typecho_Widget implements Widget_Interface_Do {
private $db;
private $res;
const LACK_PARAMETER = 'Not found';
public function __construct($request, $response, $params = NULL) {
parent::__construct($request, $response, $params);
$this->db = Typecho_Db::get();
$this->res = new Typecho_Response();
$this->apisecret = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->apiSecret;
$this->appid = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->appid;
$this->appsecret = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->appsecret;
$this->wxappid = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->wxappid;
$this->wxappsecret = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->wxappsecret;
$swipe = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->swipePosts;
if (method_exists($this, $this->request->type)) {
call_user_func(array(
$this,
$this->request->type
));
} else {
$this->defaults();
}
}
private function defaults() {
$this->export(NULL);
}
private function checkApisec($sec)
{
if(strcmp($sec,$this->apisecret) != 0) {
$this->export('API secret error');
}
}
private function posts() {
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$pageSize = (int) self::GET('pageSize', 1000);
$page = (int) self::GET('page', 1);
$authorId = self::GET('authorId', 0);
$offset = $pageSize * ($page - 1);
$getpage = self::GET('getpage', 0);
$idx = self::GET('idx',-1);
// 根据cid偏移获取文章
if (isset($_GET['cid'])) {
$cid = self::GET('cid');
if($getpage) {
$select = $this->db->select('cid', 'title', 'created', 'type', 'slug', 'text','commentsNum')->from('table.contents')->where('type = ?', 'page')->where('status = ?', 'publish')->where('created < ?', time())->order('table.contents.created', Typecho_Db::SORT_DESC)->offset($offset)->limit($pageSize);
} else {
$select = $this->db->select('cid', 'title', 'created', 'type', 'slug', 'text','commentsNum')->from('table.contents')->where('type = ?', 'post')->where('status = ?', 'publish')->where('created < ?', time())->order('table.contents.created', Typecho_Db::SORT_DESC)->offset($offset)->limit($pageSize);
}
$select->where('cid = ?', $cid);
//更新点击量数据库
$row = $this->db->fetchRow($this->db->select('views')->from('table.contents')->where('cid = ?', $cid));
$this->db->query($this->db->update('table.contents')->rows(array('views' => (int)$row['views']+1))->where('cid = ?', $cid));
}
else
{
//如果不指定具体文章CID,不抓取text
$select = $this->db->select('cid', 'title', 'created', 'type', 'slug','commentsNum')->from('table.contents')->where('type = ?', 'post')->where('status = ?', 'publish')->where('created < ?', time())->order('table.contents.created', Typecho_Db::SORT_DESC)->offset($offset)->limit($pageSize);
}
// 根据分类或标签获取文章
if (isset($_GET['category']) || isset($_GET['tag'])) {
$name = isset($_GET['category']) ? $_GET['category'] : $_GET['tag'];
$resource = $this->db->fetchAll($this->db->select('cid')->from('table.relationships')->join('table.metas', 'table.metas.mid = table.relationships.mid', Typecho_Db::LEFT_JOIN)->where('slug = ?', $name));
$cids = array();
foreach ($resource as $item) {
$cids[] = $item['cid'];
}
$select->where('cid IN ?', $cids);
}
if($idx>=0){
switch($idx)
{
case 0:
//浏览量
$select->order('table.contents.views', Typecho_Db::SORT_DESC);
break;
case 1:
//评论数
$select->order('table.contents.commentsNum', Typecho_Db::SORT_DESC);
break;
case 2:
//点赞数
$select->order('table.contents.likes', Typecho_Db::SORT_DESC);
break;
default:
break;
}
}
$posts = $this->db->fetchAll($select);
$temp = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->hiddenShare;
$author = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->author;
$website = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->website;
$account = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->account;
$result = array();
foreach ($posts as $post) {
$post = $this->widget("Widget_Abstract_Contents")->push($post);
$post['tag'] = $this->db->fetchAll($this->db->select('name')->from('table.metas')->join('table.relationships', 'table.metas.mid = table.relationships.mid', Typecho_DB::LEFT_JOIN)->where('table.relationships.cid = ?', $post['cid'])->where('table.metas.type = ?', 'tag'));
$post['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ',thumb)):array(array("str_value"=>"https://tuku.ycygame.cn/anhaowu/shoutu.png"));
$post['description'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', description))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', description)):array(array("str_value"=>"请在后台配置自定义字符isdescription"));
$post['style'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', style))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', style)):array(array("str_value"=>"3"));
$post['isPay'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', isPay))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', isPay)) :array(array("str_value"=>0));
$post['code'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', code))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', code)) :array(array("str_value"=>0));
$post['encrypted'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', encrypted))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', encrypted)) :array(array("str_value"=>""));
$post['keyword'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', keyword))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', keyword)) :array(array("str_value"=>""));
$post['views'] = $this->db->fetchAll($this->db->select('views')->from('table.contents')->where('table.contents.cid = ?', $post['cid']));
$post['likes'] = $this->db->fetchAll($this->db->select('likes')->from('table.contents')->where('table.contents.cid = ?', $post['cid']));
$post['fields'] = $this->db->fetchAll($this->db->select('name','str_value')->from('table.fields')->where('cid = ?', $post['cid']));
$post['showshare'] = $temp;
$post['author'] = $author;
$post['website'] = $website;
$post['account'] = $account;
$result[] = $post;
}
$this->export($result);
}
private function getaboutcid()
{
$cid = 'none';
$cid = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->aboutCid;
$this->export($cid);
}
private function getcat()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$temp = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->hiddenmid;
$select = $this->db->select('name','slug','type','description','mid')->from('table.metas')->where('table.metas.type = ?','category');
$hiddenmids = explode(",",$temp);
$hidden = false;
if(sizeof($hiddenmids)>0 && intval($hiddenmids[0])) {
$select->where('mid in ?', $hiddenmids);
$hidden = true;
}
$cat = $this->db->fetchAll($select);
if(!$hidden) {
$cat_recent = $cat[0];
$cat_recent['name'] = "最近发布";
$cat_recent['slug'] = "最近发布";
$cat_recent['mid'] = "99999999";
array_unshift($cat,$cat_recent);
}
$this->export($cat);
}
//首页参数 pageSize
private function recentPost() {
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$pageSize = self::GET('pageSize', 10);
$this->widget("Widget_Contents_Post_Recent", "pageSize={$pageSize}")->to($post);
$recentPost = array();
while ($post->next()) {
$recentPost[] = array(
"cid" => $post->cid,
"title" => $post->title,
"permalink" => $post->permalink
);
}
$this->export($recentPost);
}
private function likePost()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$cid = self::GET('cid', -1);
$like = self::GET('like', -1);
$openid = self::GET('openid', 'null');
$row = $this->db->fetchRow($this->db->select('likes')->from('table.contents')->where('cid = ?', $cid));
if(self::checkliked($openid,$cid)) {
//已点赞-1
$this->db->query($this->db->update('table.contents')->rows(array('likes' => (int)$row['likes']-1))->where('cid = ?', $cid));
$this->db->query($this->db->delete('table.wetypecholike')->rows(array('openid' => $openid, 'cid' => $cid))->where('openid =?', $openid)->where('cid =?', $cid));
$status = 'dislike';
}
else {
$this->db->query($this->db->update('table.contents')->rows(array('likes' => (int)$row['likes']+1))->where('cid = ?', $cid));
//更新赞数据库
$this->db->query($this->db->insert('table.wetypecholike')->rows(array('openid' => $openid, 'cid' => $cid)));
$status = 'like';
}
$likes = $this->db->fetchAll($this->db->select('likes')->from('table.contents')->where('table.contents.cid = ?', $cid));
$likes['status'] = $status;
$this->export($likes);
}
private function getuserlikedinfo()
{
$openid = self::GET('openid', 'null');
$cid = self::GET('cid', 'null');
$row = $this->db->fetchRow($this->db->select('openid','cid')->from('table.wetypecholike')->where('cid = ?', $cid)->where('openid = ?', $openid));
if(self::checkliked($openid,$cid))
{
//已存在该用户点赞
$this->export('true');
}
else
{
$this->export('false');
}
}
private function getuserlikedlist()
{
$cid = self::GET('cid', 'null');
if($cid != 'null')
{
$openids = $this->db->fetchAll($this->db->select('openid')->from('table.wetypecholike')->where('cid = ?', $cid));
foreach($openids as $openid) {
$temp = $this->db->fetchAll($this->db->select('nickname','avatarUrl')->from('table.wetypecho')->where('openid = ?', $openid));
if(sizeof($temp)>0) {
$likeinfo[] = $temp[0];
}
}
$this->export($likeinfo);
}
else
{
$this->export("No one like");
}
}
private function getfriend()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$openids = $this->db->fetchAll($this->db->select('openid')->from('table.wetypecho'));
$result = array();
foreach($openids as $openids) {
$friend = $this->db->fetchAll($this->db->select('id','openid','nickname','avatarUrl')->from('table.wetypecho'));
}
$this->export($friend);
}
private function getaccesscode()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$path = self::GET('path', 'null');
if($path == 'null') {
$path = 'page/index/index';
}
$url = sprintf('https://api.q.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s',$this->appid,$this->appsecret);
$info = file_get_contents($url);
$json = json_decode($info);
$arr = get_object_vars($json);
$accesscode = $arr['access_token'];
$url_1 = sprintf('https://api.q.qq.com/wxa/getwxacode?access_token=%s',$accesscode);
//$qrurl = $arr_t['access_token'];
$post_data = array(
'path' => $path
);
$jsonStr = json_encode($post_data);
$qrcode = $this->http_post_data($url_1, $jsonStr);
$filename = 'qrcode.png';
$write_fd = @fopen($filename,'w+');
if( fwrite($write_fd, $qrcode) ) {
fclose($write_fd);
$this->export($filename);
}
$this->export("error");
}
private function getWXaccesscode()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$path = self::GET('path', 'null');
if($path == 'null') {
$path = 'page/index/index';
}
$url = sprintf('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s',$this->wxappid,$this->wxappsecret);
$info = file_get_contents($url);
$json = json_decode($info);
$arr = get_object_vars($json);
$accesscode = $arr['access_token'];
$url_1 = sprintf('https://api.weixin.qq.com/wxa/getwxacode?access_token=%s',$accesscode);
//$qrurl = $arr_t['access_token'];
$post_data = array(
'path' => $path
);
$jsonStr = json_encode($post_data);
$qrcode = $this->http_post_data($url_1, $jsonStr);
$filename = 'qrcode.png';
$write_fd = @fopen($filename,'w+');
if( fwrite($write_fd, $qrcode) ) {
fclose($write_fd);
$this->export($filename);
}
$this->export("error");
}
function http_post_data($url, $data_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
//echo $return_content."<br>";
ob_end_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// return array($return_code, $return_content);
return $return_content;
}
private function login()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$code = self::GET('code', 'null');
if($code != 'null')
{
$nickname = self::GET('nickname', 'null');
$avatarUrl = self::GET('avatarUrl', 'null');
$city = self::GET('city', 'null');
$country = self::GET('country', 'null');
$gender = self::GET('gender', 'null');
$province = self::GET('province', 'null');
$url = sprintf('https://api.q.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code',$this->appid,$this->appsecret,$code);
$info = file_get_contents($url);
$json = json_decode($info);//对json数据解码
$arr = get_object_vars($json);
$openid = $arr['openid'];
if( $openid != null && $openid != '' ) {
$row = $this->db->fetchRow($this->db->select('openid','lastlogin')->from('table.wetypecho')->where('openid = ?', $openid));
//已存在的用户,更新上次登录时间
if(sizeof($row)>0) {
$this->db->query($this->db->update('table.wetypecho')->rows(array('lastlogin' => time()))->where('openid = ?', $openid));
$this->export($openid);
}
else {
//新用户
$this->db->query($this->db->insert('table.wetypecho')->rows(array('openid' => $openid, 'createtime' => time(), 'lastlogin' => time(), 'nickname' => $nickname, 'avatarUrl' => $avatarUrl, 'city' => $city, 'country' => $country,'gender' => $gender, 'province' => $province, 'type'=>'QQ')));
$this->export($openid);
}
} else {
$this->export('none');
}
}
else
{
$this->export("error code");
}
}
private function WXlogin()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$code = self::GET('code', 'null');
if($code != 'null')
{
$nickname = self::GET('nickname', 'null');
$avatarUrl = self::GET('avatarUrl', 'null');
$city = self::GET('city', 'null');
$country = self::GET('country', 'null');
$gender = self::GET('gender', 'null');
$province = self::GET('province', 'null');
$url = sprintf('https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code',$this->wxappid,$this->wxappsecret,$code);
$info = file_get_contents($url);
$json = json_decode($info);//对json数据解码
$arr = get_object_vars($json);
$openid = $arr['openid'];
if( $openid != null && $openid != '' ) {
$row = $this->db->fetchRow($this->db->select('openid','lastlogin')->from('table.wetypecho')->where('openid = ?', $openid));
//已存在的用户,更新上次登录时间
if(sizeof($row)>0) {
$this->db->query($this->db->update('table.wetypecho')->rows(array('lastlogin' => time()))->where('openid = ?', $openid));
$this->export($openid);
}
else {
//新用户
$this->db->query($this->db->insert('table.wetypecho')->rows(array('openid' => $openid, 'createtime' => time(), 'lastlogin' => time(),
'nickname' => $nickname, 'avatarUrl' => $avatarUrl, 'city' => $city, 'country' => $country,
'gender' => $gender, 'province' => $province, 'type'=>'微信')));
$this->export($openid);
}
} else {
$this->export('none');
}
}
else
{
$this->export("error code");
}
}
private function addcomment()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$cid = self::GET('cid', -1);
$author = self::GET('author', "None");
$text = self::GET('text', "None");
$parent = self::GET('parent', 0);
$headicon = self::GET('icon', "NULL");
$coid =$this->db->query($this->db->insert('table.comments')->rows(array('cid' => $cid, 'created' => time(), 'author' => $author, 'authorId' => '0',
'ownerId' => '1', 'mail' => '480839154@qq.com', 'url' => 'https://www.i4qq.com', 'ip' =>'8.8.8.8', 'agent' => 'miniprogram', 'text' => $text, 'type' => 'comment',
'status' => 'approved', 'parent' => $parent,
'authorImg' => $headicon,'status' => 'waiting' )));
if($coid>0) {
$row = $this->db->fetchRow($this->db->select('commentsNum')->from('table.contents')->where('cid = ?', $cid));
$this->db->query($this->db->update('table.contents')->rows(array('commentsNum' => (int)$row['commentsNum']+1))->where('cid = ?', $cid));
}
$this->export($coid);
}
private function checkliked($openid,$cid)
{
$row = $this->db->fetchRow($this->db->select('openid','cid')->from('table.wetypecholike')->where('cid = ?', $cid)->where('openid = ?', $openid));
if(sizeof($row)>0)
{
//已存在该用户点赞
return 1;
}
else
{
return 0;
}
}
private function getpostbymid()
{
$sec = self::GET('apisec', 'null');
$count = self::GET('count', 10);
self::checkApisec($sec);
$pageSize = (int) self::GET('pageSize', 1000);
$except = (int) self::GET('except', 'null');
$mid = self::GET('mid', -1);
$select = [];
if($mid == 99999999) {
$posts = $this->db->fetchAll($this->db->select('cid', 'title', 'created', 'type', 'slug','commentsNum')->from('table.contents')->where('type = ?', 'post')->where('status = ?', 'publish')->where('created < ?', time())->order('table.contents.created', Typecho_Db::SORT_DESC)->limit($count));
foreach($posts as $post) {
$temp = $this->db->fetchAll($this->db->select('cid', 'title', 'created','commentsNum', 'views', 'likes')->from('table.contents')->where('cid = ?', $post['cid'])->where('status = ?', 'publish'));
if(sizeof($temp)>0) {
$temp['0']['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ',thumb)):array(array("str_value"=>"https://tuku.ycygame.cn/anhaowu/shoutu.png"));
$temp['fields'] = $this->db->fetchAll($this->db->select('name','str_value')->from('table.fields')->where('cid = ?', $post['cid']));
$temp['0']['description'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', description))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', description)):array(array("str_value"=>"请在后台配置自定义字符description"));
array_push($select,$temp[0]);
}
}
if(sizeof($posts)>0) {
$this->export($select);
} else {
$this->export(null);
}
}
else if($mid>=0)
{
$limit = 0;
if($except != 'null') {
$posts = $this->db->fetchAll($this->db->select('cid','mid')->from('table.relationships')->where('mid = ?', $mid)->where('cid != ?', $except));
} else {
$posts = $this->db->fetchAll($this->db->select('cid','mid')->from('table.relationships')->where('mid = ?', $mid));
}
foreach($posts as $post) {
$temp = $this->db->fetchAll($this->db->select('cid', 'title', 'created','commentsNum', 'views', 'likes')->from('table.contents')->where('cid = ?', $post['cid'])->where('status = ?', 'publish'));
if(sizeof($temp)>0) {
$temp['0']['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ',thumb)):array(array("str_value"=>"https://tuku.ycygame.cn/anhaowu/shoutu.png"));
$temp['0']['description'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', description))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])->where('name = ? ', description)):array(array("str_value"=>"请在后台配置自定义字符description"));
array_unshift($select,$temp[0]);
}
$limit++;
}
$overflow = sizeof($select) - $pageSize;
for($cnt = 0; $cnt < $overflow; $cnt++) {
array_pop($select);
}
if(sizeof($posts)>0) {
$this->export($select);
} else {
$this->export(null);
}
}
$this->export(null);
}
private function search()
{
$keyword = self::GET('keyword', 'null');
if($keyword != 'null')
{
$cids = $this->db->fetchAll($this->db->select('cid')->from('table.contents')->where('text LIKE ?', '%' . $keyword . '%'));
if(sizeof($cids)>0){
foreach($cids as $cid) {
$post = $this->db->fetchAll($this->db->select('cid', 'title', 'created', 'type', 'slug','commentsNum')->from('table.contents')->where('cid = ?', $cid)->where('type = ?', 'post')->where('status = ?', 'publish')->where('created < ?', time()));
if(sizeof($post)>0 && $post[0]!=null) {
$post[0] = $this->widget("Widget_Abstract_Contents")->push($post[0]);
$post[0]['tag'] = $this->db->fetchAll($this->db->select('name')->from('table.metas')->join('table.relationships', 'table.metas.mid = table.relationships.mid', Typecho_DB::LEFT_JOIN)->where('table.relationships.cid = ?', $cid)->where('table.metas.type = ?', 'tag'));
$post[0]['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ',thumb)):array(array("str_value"=>"https://tuku.ycygame.cn/anhaowu/shoutu.png"));
$post['0']['description'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ', description))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $cid)->where('name = ? ', description)):array(array("str_value"=>"请在后台配置自定义字符description"));
$post[0]['views'] = $this->db->fetchAll($this->db->select('views')->from('table.contents')->where('table.contents.cid = ?', $cid));
$post[0]['likes'] = $this->db->fetchAll($this->db->select('likes')->from('table.contents')->where('table.contents.cid = ?', $cid));
$result[] = $post[0];
}
}
if(sizeof($result)>0) {
$this->export($result);
} else {
$this->export("none");
}
} else {
$this->export("none");
}
}
else
{
$this->export(null);
}
}
private function getswiperpost()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$swipe = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->swipePosts;
$cids = explode(",",$swipe);
$result = array();
if(sizeof($cids)>0){
foreach($cids as $cid) {
$post = $this->db->fetchAll($this->db->select('cid', 'title', 'created', 'type', 'slug','commentsNum')->from('table.contents')->where('cid = ?', $cid)->where('status = ?', 'publish')->where('type = ?', 'post')->where('created < ?', time()));
if(sizeof($post)>0 && $post[0]!=null) {
$post[0] = $this->widget("Widget_Abstract_Contents")->push($post[0]);
$post[0]['tag'] = $this->db->fetchAll($this->db->select('name')->from('table.metas')->join('table.relationships', 'table.metas.mid = table.relationships.mid', Typecho_DB::LEFT_JOIN)->where('table.relationships.cid = ?', $cid)->where('table.metas.type = ?', 'tag'));
$post[0]['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('table.fields.cid = ?', $cid)->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('table.fields.cid = ?',$cid)->where('name = ? ',thumb)):array(array("str_value"=>"https://tuku.ycygame.cn/anhaowu/shoutu.png"));
$post[0]['views'] = $this->db->fetchAll($this->db->select('views')->from('table.contents')->where('table.contents.cid = ?', $cid));
$post[0]['likes'] = $this->db->fetchAll($this->db->select('likes')->from('table.contents')->where('table.contents.cid = ?', $cid));
$result[] = $post[0];
}
}
if(sizeof($result)>0) {
$this->export($result);
} else {
$this->export(null);
}
} else {
$this->export(null);
}
}
private function getrecommend()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$rec = Typecho_Widget::widget('Widget_Options')->plugin('WeTypecho')->recommend;
$cids = explode(",",$rec);
$result = array();
if(sizeof($cids)>0){
foreach($cids as $cid) {
$post = $this->db->fetchAll($this->db->select('cid', 'title', 'created', 'type', 'slug','commentsNum')->from('table.contents')->where('cid = ?', $cid)->where('status = ?', 'publish')->where('type = ?', 'post')->where('created < ?', time()));
if(sizeof($post)>0 && $post[0]!=null) {
$post[0] = $this->widget("Widget_Abstract_Contents")->push($post[0]);
$post[0]['tag'] = $this->db->fetchAll($this->db->select('name')->from('table.metas')->join('table.relationships', 'table.metas.mid = table.relationships.mid', Typecho_DB::LEFT_JOIN)->where('table.relationships.cid = ?', $cid)->where('table.metas.type = ?', 'tag'));
$post[0]['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('table.fields.cid = ?', $cid)->where('name = ? ',thumb))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('table.fields.cid = ?',$cid)->where('name = ? ',thumb)):array(array("str_value"=>"https://tuku.ycygame.cn/anhaowu/shoutu.png"));
$post[0]['views'] = $this->db->fetchAll($this->db->select('views')->from('table.contents')->where('table.contents.cid = ?', $cid));
$post[0]['likes'] = $this->db->fetchAll($this->db->select('likes')->from('table.contents')->where('table.contents.cid = ?', $cid));
$result[] = $post[0];
}
}
if(sizeof($result)>0) {
$this->export($result);
} else {
$this->export(null);
}
} else {
$this->export(null);
}
}
private function getcomment()
{
$sec = self::GET('apisec', 'null');
self::checkApisec($sec);
$cid = self::GET('cid', -1);
$comments = $this->db->fetchAll($this->db->select('cid','coid','created', 'author', 'text', 'parent', 'authorImg')->from('table.comments')->where('cid = ?', $cid)->where('status = ?', 'approved')->order('table.comments.created', Typecho_Db::SORT_DESC));
$result = array();
//获取根评论
foreach ($comments as $comment) {
if($comment['parent'] == 0) {
$result[] = $comment;
}
}
//获取子评论
foreach($comments as $comment) {
if($comment['parent'] != 0) {
$parent = $comment['parent'];
$temp = $this->db->fetchAll($this->db->select('cid','coid','created', 'author', 'text', 'parent', 'authorImg')->from('table.comments')->where('cid = ?', $cid)->where('coid = ?', $parent)->where('status = ?', 'approved')->order('table.comments.created', Typecho_Db::SORT_DESC));
if(sizeof($temp)>0)
{
while($temp[0]['parent']!=0)
{
$parent = $temp[0]['parent'];
$temp = $this->db->fetchAll($this->db->select('cid','coid','created', 'author', 'text', 'parent', 'authorImg')->from('table.comments')->where('cid = ?', $cid)->where('coid = ?', $parent)->where('status = ?', 'approved')->order('table.comments.created', Typecho_Db::SORT_DESC));
}
for($i=0; $i<sizeof($result);$i++)
{
if($result[$i]['coid'] == $temp[0]['coid']) {
$comment['parentitem'] = $this->db->fetchAll($this->db->select('cid','coid','created', 'author', 'text', 'parent', 'authorImg')->from('table.comments')->where('cid = ?', $cid)->where('coid = ?', $comment['parent'])->where('status = ?', 'approved')->order('table.comments.created', Typecho_Db::SORT_DESC));
$result[$i]['replays'][] = $comment;
}
}
}
}
}
$this->export($result);
}
public function export($data = array(), $status = 200) {
if($data!=[]){
$this->res->throwJson(array(
'status' => $status,
'data' => $data
));
exit;}
else{
$this->res->throwJson(array(
'status' => '403',
'data' => 'NULL'
));
exit;
}
}
public static function GET($key, $default = '') {
return isset($_GET[$key]) ? $_GET[$key] : $default;
}
public function action() {
$this->on($this->request);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/Byclemon/Pisces-Wetypecho.git
git@gitee.com:Byclemon/Pisces-Wetypecho.git
Byclemon
Pisces-Wetypecho
Pisces-Wetypecho
master

搜索帮助