您的位置:首页 > 其它

SupeSite后台添加新闻增加【预览】功能

2012-07-05 15:08 316 查看
SupeSite后台添加新闻增加【预览】功能
实现目的:为了添加新闻时候更方便!

实现原因:添加新闻时候可能有些样式会出现错误,生成静态页之后再去看的时候会比较浪费时间。

实现步骤:

1.在后台找到admin/tpl/spacenews.hml

2.在<div class="buttons">

加一行:

<input type="button" value="预览一下" style="color:red;font-size:16px">

</div>

3.在当前文件底部用ajax方法方法跳转

<script language="javascript" type="text/javascript">

function yulan(){

//分别获得你想要的值 去表单中相对应的id值

var subject = jq("#sub").val();

var newsauthor =jq("#new").val();

var newsfrom = jq("#from").val()

//获得编辑器中的值注意

et.save();

var message = jq("[name^=me]").val();

jq.ajax({

url:"admincp.php?action=控制器&type=$type&op=方法",//传到的控制器和方法中

data:"subject="+sub+"&newsr="+news+"&from="+from+"&me="+me,

type:"post",

dataType:"html",

success:function(info){

var a = window.open("html/yulan/yulan"+info+".htm");//返回值并弹出新窗口中预览

}

})

}

</script>

4.在对应的控制器中写相对应的方法即可(注意:因为用的是$_GET['po=方法名']所以尽量在模版对应的控制器中写)

elseif ($_GET['op'] == 'yulan'){

//判读需要的目录是否存在

if(!is_dir(S_ROOT.'./html/yulan')){

mkdir(S_ROOT.'./html/yulan',0777);

}

//获得当前用户的UID方便区别模版生成时的名字

$filenameuid=$_SGLOBAL['supe_uid'];

//获得分类catid

$catid=$_POST['catid'];

$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('categories')." WHERE catid='$catid'");

//遍历之后得到 分类首页模版 的 tpl值

$thecat = $_SGLOBAL['db']->fetch_array($query);

//判断 分类首页模版 的 tpl不为空 &&(和)检查文件是否存在 (针对于资讯分类----预览功能)

if(!empty($thecat['viewtpl']) && file_exists(S_ROOT.'./templates/'.$_SCONFIG['template'].'/'.$thecat['viewtpl'].'.html.php')) { //分类名字

$tplname = $thecat['viewtpl'];

}else {

//判断频道菜单名字 频道类型 频道tpl(分类)(和)检查文件是否存在 (针对于资讯管理----预览频道)

if(!empty($channels['menus'][$thecat['type']]['viewtpl']) && file_exists(S_ROOT.'./templates/'.$_SCONFIG['template'].'/'.$channels['menus'][$thecat['type']]['viewtpl'].'.html.php')) {

//分类名字

$tplname = $channels['menus'][$thecat['type']]['viewtpl'];

}else {

//分类名字

$tplname = 'news_view';

}

}

//分别赋值到前台的模版中

$channelname = $channels['menus'][$channel]['name'];

$news[subject] = shtmlspecialchars(trim($_POST['subject']));

$news[newsfrom] = shtmlspecialchars(trim($_POST['newsfrom']));

$news[newsauthor] = shtmlspecialchars(trim($_POST['newsauthor']));

$news[message] = stripcslashes($_POST['message']);

ob_clean();

include template($tplname);

$yl = ob_get_contents();

file_put_contents("html/yulan/yulan$filenameuid.htm",$yl);

ob_clean();

echo $filenameuid;

exit;

}

本文出自 “随心所欲” 博客,请务必保留此出处http://confi.blog.51cto.com/5271328/920756
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐