Skip to content

Commit

Permalink
新增豆瓣电影,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lijianxiong committed Feb 21, 2019
1 parent 94683b1 commit 6e2c525
Show file tree
Hide file tree
Showing 21 changed files with 616 additions and 119 deletions.
7 changes: 6 additions & 1 deletion application/admin/controller/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,16 @@ public function autoSave(){
'msg' => '未知原因,自动保存失败'
];
}else{
$id = $result->id;
$msg = [
'status' => 1001,
'msg' => '自动保存成功',
'id' => $result->id
'id' => $id
];
AdditionalModel::create([
'user_id' => $this->userId(),
'article_id' => $id
]);
}
return $msg;
}else{
Expand Down
5 changes: 4 additions & 1 deletion application/admin/controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use app\common\model\User as UserModel;
use app\common\model\Safecode as SafecodeModel;
use app\common\model\Invitationcode as InviModel;
use app\common\model\Site as SiteModel;

class Login extends Controller
{
Expand Down Expand Up @@ -149,11 +150,13 @@ public function senCode(){
}

public function sendPassword($safeCode,$email){
$blogInfo = SiteModel::where('type','site_setting')->value('value');
$blogUrl = json_decode($blogInfo,true);
$this->assign([
'title' => '发送重置密码链接'
]);
if ($safeCode){
$content = '<a href="http://nblog.199508.com/admin/login/setpassword?safe_code='.$safeCode.'&email='.$email.'">点击重置密码</a>';
$content = '<a href="'.$blogUrl['site_url'].'/admin/login/setpassword?safe_code='.$safeCode.'&email='.$email.'">点击重置密码</a>';
$sendEmail = new Mailhelper();
$sendEmail->sendMail($email,'找回密码,系统邮件请勿直接回复',$content);
return $this->tips('安全码已经发送至'.$email.'请注意查收!','success',5,'/admin/login');
Expand Down
17 changes: 17 additions & 0 deletions application/common/model/Douban.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: nobita
* Date: 2/16
* Time: 16:20
*/

namespace app\common\model;


use think\Model;

class Douban extends Model
{

}
3 changes: 2 additions & 1 deletion application/index/controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function listItemThumbnail($fileNames,$width,$height)

public function sendMail($to = [], $subject = '', $content = '')
{
$config = config('email');
$siteEmail = SiteModel::where('type','site_email')->value('value');
$config = json_decode($siteEmail,true);
$mail = new Message();
if (empty($config['host']) || empty($config['username']) || empty($config['password'])) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions application/index/controller/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function index($page = 1)
{
$path = url('/index/');
$articleList = ArticleModel::where('status', 1)
->where('del',NULL)
->order('create_time', 'desc')
->paginate(10, true, [
'page' => $page,
Expand Down Expand Up @@ -66,12 +67,16 @@ public function post($id)
->where('type','article')
->order('time', 'asc')
->select();
$commentNum = CommentModel::where('value', $id)
->where('type','article')
->count();
$articleData['comment'] = $commentData;
$resultData = $this->articleFormatConversion($articleData);
$this->assign([
'title' => $resultData['article']['title'],
'article' => $resultData['article'],
'comment' => $resultData['comment'],
'commentNum' => $commentNum,
'userId' => $this->_N['session']['id']
]);
return $this->view->fetch('/post');
Expand Down
40 changes: 39 additions & 1 deletion application/index/controller/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use app\common\model\Article as ArticleModel;
use app\common\model\Dynamic as DynamicModel;
use app\common\model\Comment as CommentModel;
use app\common\model\Douban as DoubanModel;

class Page extends Base
{
Expand Down Expand Up @@ -44,6 +45,39 @@ public function album($page = 1)
return $this->view->fetch('/album');
}

public function douBan($page = 1){
$path = url('/douban/');
$douBanData = DoubanModel::where('status', 1)
->order('create_time', 'desc')
->paginate(18, true, [
'page' => $page,
'path' => $path . '[PAGE]'
]);
$articleSum = DoubanModel::count();
$page = $douBanData->render();
$movieResult = $this->douBanFormat($douBanData);
$this->assign([
'title' => '看过的电影',
'page' => $page,
'article' => $movieResult,
'sum' => $articleSum
]);
return $this->view->fetch('/douban');
}

public function douBanFormat($data){
$movieList = [];
foreach ($data as $key=>$item) {
$content = json_decode($item['content'],true);
$movieList[$key]['title'] = $content['title'];
$movieList[$key]['alt'] = $content['alt'];
$movieList[$key]['images'] = $content['images']['large'];
$movieList[$key]['rating'] = $content['rating']['average'];

}
return $movieList;
}

public function reachAlbum($content, $id, $title)
{
$pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.BMP|\.JPG|\.PNG]))[\'|\"].*?[\/]?>/";
Expand Down Expand Up @@ -149,11 +183,15 @@ public function dynamicPost($id)
]);
$articleData['comment'] = $commentData;
$resultData = $this->dynamicFormConversion($articleData);
$commentNum = CommentModel::where('value', $id)
->where('type','d')
->count();
$this->assign([
'title' => '动态',
'article' => $resultData['article'],
'comment' => $resultData['comment'],
'userId' => $this->_N['session']['id']
'userId' => $this->_N['session']['id'],
'commentNum' => $commentNum
]);
return $this->view->fetch('/dynamic/post');
}
Expand Down
68 changes: 68 additions & 0 deletions application/index/controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use app\common\model\Comment as CommentModel;
use app\common\model\Visitor as VisitorModel;
use app\common\model\Additional as AdditionalModel;
use app\common\model\Douban as DoubanModel;
use app\common\model\Msg as MsgModel;

class User extends Auth
Expand Down Expand Up @@ -209,4 +210,71 @@ public function write($id=0){
]);
return $this->view->fetch('/user/write');
}

public function douBan($page = 1){
$path = url('/profile/douban/');
$douBanData = DoubanModel::where('user_id',$this->userId())
->order('create_time', 'desc')
->paginate(12, true, [
'page' => $page,
'path' => $path . '[PAGE]'
]);
$movieResult = $this->douBanFormat($douBanData);
$page = $douBanData->render();
$this->assign([
'title' => '豆瓣电影',
'data' => $movieResult,
'page' => $page
]);
return $this->view->fetch('/user/douban');
}

public function douBanFormat($data){
$movieList = [];
foreach ($data as $key=>$item) {
$content = json_decode($item['content'],true);
$movieList[$key]['title'] = $content['title'];
$movieList[$key]['alt'] = $content['alt'];
$movieList[$key]['images'] = $content['images']['large'];
$movieList[$key]['rating'] = $content['rating']['average'];

}
return $movieList;
}

public function getDouBan(){
$data = input('post.');
$id = htmlspecialchars($data['id']);
$getUrl = 'https://api.douban.com/v2/movie/subject/'.$id;
$result = file_get_contents($getUrl);
$haveId = DoubanModel::where('user_id',$this->userId())->where('movie_id',$id)->value('movie_id');
if (!empty($haveId)){
$msg = [
'status' => 1002,
'msg' => '电影已经存在添加失败'
];
return $msg;
}else{

$result = DoubanModel::create([
'user_id' => $this->userId(),
'movie_id' => $id,
'content' => $result,
'create_time' => time()
]);
if ($result){
$msg = [
'status' => 1001,
'msg' => '电影添加成功'
];
return $msg;
}else{
$msg = [
'status' => 1002,
'msg' => '电影添加失败'
];
return $msg;
}
}
}
}
3 changes: 3 additions & 0 deletions application/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Route::post('links/register', 'page/linksRegister');
Route::get('archives/[:page]', 'page/archives');
Route::get('album/[:page]', 'page/album');
Route::get('douBan/[:page]', 'page/douBan');
Route::get('category/[:id]', 'category/index');
Route::get('category/[:id]/page/[:page]', 'category/index');
Route::post('comment/post', 'comment/post');
Expand All @@ -47,6 +48,8 @@
Route::get('profile/edit', 'user/edit');
Route::get('profile/msg/[:page]', 'user/msg');
Route::get('profile/write/[:id]', 'user/write');
Route::get('profile/douBan/[:page]', 'user/douBan');
Route::post('profile/getDouBan', 'user/getDouBan');


Route::get('dynamic', 'page/dynamic');
Expand Down
15 changes: 11 additions & 4 deletions public/theme/adminv2/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,36 @@
<div class="row">
<div class="radio col-lg-6">
<label>
<input type="radio" name="ssl" value="ssl" <?=$siteEmail['ssl'] == 'ssl'?'checked':''?>> 使用SSL
<input type="radio" name="secure" value="ssl" <?=$siteEmail['secure'] == 'ssl'?'checked':''?>> 使用SSL
</label>
</div>
<div class="radio col-lg-6">
<label>
<input type="radio" name="ssl" value="not" <?=$siteEmail['ssl'] == 'not'?'checked':''?>> 不需要
<input type="radio" name="secure" value="not" <?=$siteEmail['secure'] == 'not'?'checked':''?>> 不需要
</label>
</div>
</div>
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 form-control-label">发件人名称</label>
<div class="col-sm-9">
<input id="nickname" type="text" name="nickname" placeholder="" class="form-control form-control-success" value="<?=$siteEmail['nickname'];?>">
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 form-control-label">发件人邮箱地址</label>
<div class="col-sm-9">
<input id="post_email" type="text" name="post_email" placeholder="" class="form-control form-control-success" value="<?=$siteEmail['post_email'];?>">
<input id="post_email" type="text" name="username" placeholder="" class="form-control form-control-success" value="<?=$siteEmail['username'];?>">
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 form-control-label">发件人邮箱密码</label>
<div class="col-sm-9">
<input id="post_password" type="text" name="post_password" placeholder="" class="form-control form-control-success" value="<?=$siteEmail['post_password'];?>">
<input id="post_password" type="text" name="password" placeholder="" class="form-control form-control-success" value="<?=$siteEmail['password'];?>">
</div>
</div>
<div class="form-group text-center">
Expand Down
3 changes: 2 additions & 1 deletion public/theme/nobita/album.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="nobita-post-list">
<div class="n-post-list">
<div class="n-archives-header-title">
<h4>生活圈 <span class="n-sum-archives">共有<?=$sum;?> 张照片</span></h4>
<h4>生活圈 <span class="n-sum-archives">共有<?= $sum; ?> 张照片</span></h4>
</div>
<div class="n-album-list">
<?php foreach ($article as $item): ?>
Expand All @@ -11,6 +11,7 @@
<div class="n-album-thumb" style="
background-image: url(<?= $item['thumb']; ?>);
"></div>
<div class="n-album-title"><?= $item['title']; ?></div>
</a>
</div>
<?php endforeach; ?>
Expand Down
Loading

0 comments on commit 6e2c525

Please sign in to comment.