public function actionChangetemplate() {
$status=true;
$interactive_id= (int)filter_input(INPUT_POST,'id');//post[id]
$template_id= (int) filter_input(INPUT_POST, 'mb');
//找到页
$interactives = Interactives::model ()->findByPk ( $interactive_id );
//获取模板
$interactiveTemplate = InteractiveTemplate::model ()->findByPk ( $template_id );
//修改模板
$interactives->template_id =$template_id;
$interactives->save();
// 根据用户选择的模板来设置不同的内容
$template_info = $interactiveTemplate->template_content;
$interactiveContent = new InteractiveContent ();
$interactivePic = new InteractivePic();
//添加内容,以下根据content进行正则表达式匹配,生成相对应的content
if (preg_match_all ( '/preview_t_[0-9]+/', $template_info, $arr )) {
//删除
$res = InteractiveContent::model ()->deleteAll ("interactive_id=:ID",array(
":ID"=>$interactive_id
) );
foreach ($arr[0] as $key=>$value){
$content = new InteractiveContent ();
$content->interactive_id =$interactive_id;
$content->color = "rgba(0,0,0,0.1)";
$content->content = '<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:24px;\"><strong>文本输入框<\/strong><\/span>\n<\/p>\n<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:16px;\">您可以进行文本输入、复制、黏贴;调整字体大小、颜色、对齐、行间距;也可以对文本框本身设置相应的背景颜色以及透明度。<\/span>\n<\/p>';
$content->c_time = date ( "y-m-d H:i:s" );
$ret=$content->save ();
if($ret>0)//如果正确,则结果为true
$status=$status&true;
else
$status=$status&false;
}
}
//添加图片
if (preg_match_all ( '/preview_p_[0-9]+/', $template_info, $arr )) {
//删除
$res = InteractivePic::model ()->deleteAll ("interactive_id=:ID",array(
":ID"=>$_POST ['id']
) );
for($i = 1; $i <= count ( $arr[0] ); $i ++) {
$interactivePic = new InteractivePic();
$interactivePic->interactive_id = $_POST ['id'];
$interactivePic->pic_scale = 2.2;
$interactivePic->pic_src = "/images/editinteractive/pcover_000.jpg";
$interactivePic->pic_width = 30;
$interactivePic->pic_height =30;
$interactivePic->pic_x = 0;
$interactivePic->pic_y =0;
$interactivePic->tag = $i;
$interactivePic->c_time = date ( "y-m-d H:i:s" );
$ret=$interactivePic->save();
if($ret>0)//如果正确,则结果为true
$status=$status&true;
else
$status=$status&false;
}
}
if (preg_match_all ( '/preview_s1_1_p[0-9]+/', $template_info, $arr )) {
//删除
$res = InteractivePic::model ()->deleteAll ("interactive_id=:ID",array(
":ID"=>$_POST ['id']
) );
for($i = 1; $i <= count ( $arr[0] ); $i ++) {
$interactivePic = new InteractivePic();
$interactivePic->interactive_id = $_POST ['id'];
$interactivePic->pic_scale = 2.2;
$interactivePic->pic_src = "/images/editinteractive/pcover_000.jpg";
$interactivePic->pic_width = 33;
$interactivePic->pic_height =44;
$interactivePic->pic_x = 33;
$interactivePic->pic_y =44;
$interactivePic->tag = 33;
$interactivePic->c_time = date ( "y-m-d H:i:s" );
$ret=$interactivePic->save();
if($ret>0)//如果正确,则结果为true
$status=$status&true;
else
$status=$status&false;
}
}
if (preg_match_all ( '/preview_s1_1_t[0-9]+/', $template_info, $arr )) {
//删除
$res = InteractiveContent::model ()->deleteAll ("interactive_id=:ID",array(
":ID"=>$_POST ['id']
) );
foreach ($arr[0] as $key=>$value){
$content = new InteractiveContent ();
$content->interactive_id = $_POST ['id'];
$content->color = "rgba(0,0,0,0.1)";
$content->content = '<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:24px;\"><strong>文本输入框<\/strong><\/span>\n<\/p>\n<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:16px;\">您可以进行文本输入、复制、黏贴;调整字体大小、颜色、对齐、行间距;也可以对文本框本身设置相应的背景颜色以及透明度。<\/span>\n<\/p>';
$content->c_time = date ( "y-m-d H:i:s" );
$ret=$content->save ();
if($ret>0)//如果正确,则结果为true
$status=$status&true;
else
$status=$status&false;
}
}
if (preg_match_all ( '/preview_s1_1_t_[0-9]+/', $template_info, $arr )) {
//删除
$res = InteractiveContent::model ()->deleteAll ("interactive_id=:ID",array(
":ID"=>$_POST ['id']
) );
foreach ($arr[0] as $key=>$value){
$content = new InteractiveContent ();
$content->interactive_id = $_POST ['id'];
$content->color = "rgba(0,0,0,0.1)";
$content->content = '<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:24px;\"><strong>文本输入框<\/strong><\/span>\n<\/p>\n<p style=\"text-align:left;\">\n\t<span style=\"color:#000000;line-height:1.5;font-size:16px;\">您可以进行文本输入、复制、黏贴;调整字体大小、颜色、对齐、行间距;也可以对文本框本身设置相应的背景颜色以及透明度。<\/span>\n<\/p>';
$content->c_time = date ( "y-m-d H:i:s" );
$ret=$content->save ();
if($ret>0)//如果正确,则结果为true
$status=$status&true;
else
$status=$status&false;
}
}
if ($status) {
echo json_encode ( array (
//success
'status' => 'success'
) );
} else {
echo json_encode ( array (
'status' => 'fail'
) );
}
}
来源:
http://myfetish.cn/
获取模板函数
最新推荐文章于 2023-12-25 22:13:20 发布