public function createPublicPost(array $post) { if (empty($post['blog_id']) || empty($post['user_id'])) { $this->addError('blog_id', Yii::t('BlogModule.blog', "Blog is empty!")); return false; } $blog = Blog::model()->get((int) $post['blog_id'], []); if (null === $blog) { $this->addError('blog_id', Yii::t('BlogModule.blog', "You can't write in this blog!")); return false; } if ($blog->isPrivate() && !$blog->isOwner($post['user_id'])) { $this->addError('blog_id', Yii::t('BlogModule.blog', "You can't write in this blog!")); return false; } if (!$blog->isPrivate() && !$blog->userIn($post['user_id'])) { $this->addError('blog_id', Yii::t('BlogModule.blog', "You can't write in this blog!")); return false; } $this->setAttributes($post); $this->setTags($post['tags']); $this->publish_time = date('d-m-Y h:i'); $this->status = $post['status'] == self::STATUS_DRAFT ? self::STATUS_DRAFT : $blog->post_status; return $this->save(); }