form();
}
/**
* 保存
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function store()
{
return $this->form()->saving(function (Form $form) {
global $__MINI_GLOBAL_TENANT_ID__;
if($__MINI_GLOBAL_TENANT_ID__ > 0){
return $this->fail(416001);
}
$posts_title = trim((strip_tags(_empty_default_($form->posts_title, ''))));
$posts_content = $form->posts_content;
$user_id = (int)($form->user_id);
$circle_id = $form->circle_id;
$tenant_id = $form->tenant_id;
if(_empty_($tenant_id)){
$tenant_id = 0;
}
$tags = $form->tags;
$img_urls = $form->img_urls;
$video = $form->video;
$goods = $form->goods;
$address_id = $form->address_id;
$data = ['posts_content'=>$posts_content, 'user_id'=>$user_id,
'circle_id'=>$circle_id, 'tags'=>$tags, 'img_urls'=>$img_urls,
'video'=>$video, 'goods'=>$goods, 'address_id'=>$address_id];
$form->data__ = json_encode($data);
$posts_content_raw = preg_replace("/<(img|video).*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", '',$posts_content);
if( ( strlen($posts_content_raw) != strlen($posts_content) ) || mb_strlen($posts_content_raw) > 2000 ){
if(!_empty_($video)){
$posts_content .= '';
}else if(!_empty_($img_urls)){
$img_arr = explode(',', $img_urls);
if($img_arr){
foreach ($img_arr as $url){
$posts_content .= '';
}
}
}
}
$posts_content = PostUtils::post_icon_inline_process($posts_content);
// $posts_content = CollecterUtils::content_media_process( $posts_content, 1);
$res = PostsRepositores::admin_add('', $user_id, $posts_title, $posts_content, $circle_id, $tags, $goods, $img_urls, $video, $address_id, '', '', $tenant_id);
if ($res) {
CalculateLikesNumJob::dispatch($res);
CalculateFollowsNumJob::dispatch($user_id);
UpdatePostOnlyTextJob::dispatch(0);
// 清空缓存
$form->multipleSteps()->flushStash();
// 拦截保存操作
return response(
$form->multipleSteps()
->done()
->render()
);
} else {
// 抛出错误
return $this->fail(416001, $res);
}
})->store();
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(null, function (Form $form) {
$form->action('/posts/publish/step');
$form->disableListButton();
$form->multipleSteps()
->remember() // 记住表单步骤,默认不开启
->width('950px')
->add('基本信息', function (StepForm $step) {
if(__system_is_model_enable('ycookies', 'caijiwebinfo')) {
$step->caijiwebinfo('采集web信息')->titleClass('art_title') // 插入文章标题到对应的class
->contentClass('art_content'); // 插入文章内容到对应的class;
}
$step->html(function (){
return '