Esempio n. 1
0
 public static function edit(BlogForm $blogform)
 {
     $uid = \Yii::$app->user->getId();
     $blog = Blog::findOne(['id' => $blogform->id, 'uid' => $uid]);
     $blog->title = htmlspecialchars($blogform->title);
     $blog->content = htmlspecialchars($blogform->content);
     if ($blog->tags != $blogform->tags) {
         $updateTags = true;
     }
     /*
     		if ($blogform->status == self::STATUS_PUBLISH && $blog->status != self::STATUS_PUBLISH) {
     			$countInc = true;
     		}
     		if ($blogform->status != self::STATUS_PUBLISH && $blog->status == self::STATUS_PUBLISH) {
     			$countDec = true;
     		}
     */
     $analyse = self::analyse($blogform->content);
     if (!$blogform->description) {
         $blog->description = $analyse['description'];
     } else {
         $blog->description = $blogform->description;
     }
     //$blog->image = $blogform->image ? $blogform->image : $analyse['image'];
     $blog->image = $analyse['image'];
     $blog->thumb = $analyse['thumb'];
     $blog->tags = $blogform->tags;
     $blog->cid = $blogform->cid;
     $blog->status = $blogform->status ? $blogform->status : self::STATUS_PUBLISH;
     $blog->is_private = is_numeric($blogform->is_private) ? $blogform->is_private : 0;
     $blog->allow_review = is_numeric($blogform->allow_review) ? $blogform->allow_review : 1;
     $blog->uptime = time();
     $res = $blog->save();
     if ($res) {
         if (isset($updateTags) && $updateTags) {
             Tags::removeByBlogId($id);
             Tags::add($blog->tags, $id);
         }
         return true;
     }
     return false;
 }
Esempio n. 2
0
 public function actionTofocus()
 {
     $post = \Yii::$app->request->post();
     if (empty($post['blog_id']) || empty($post['title']) || empty($post['image'])) {
         return $this->ajaxReturn('参数错误', false);
     }
     $blog = Blog::findOne(intval($post['blog_id']));
     if (!$blog) {
         return $this->ajaxReturn('此博客不存在', false);
     }
     if (!file_exists($post['image'])) {
         return $this->ajaxReturn('图片不存在', false);
     }
     if ($blog->is_private == 1 || $blog->status != Blog::STATUS_PUBLISH) {
         return $this->ajaxReturn('此博客不能添加到焦点图', false);
     }
     if (Focus::exist($post['blog_id'], $post['type'])) {
         return $this->ajaxReturn('此焦点图已存在', false);
     }
     //先裁剪
     $size = Focus::getSize();
     $post['image'] = $this->thumb($post['image'], $size[0], $size[1]);
     if (Focus::add($post)) {
         $blog->is_focus = 1;
         if ($blog->save()) {
             return $this->ajaxReturn('操作成功');
         } else {
             return $this->ajaxReturn('操作失败', false);
         }
     }
     return $this->ajaxReturn('操作失败', false);
 }