开发一个功能

该问题为悬赏问题,赏金为:88.00元 已由 fesiong 领取 赏金说明
现在有一个需求  
就是对于 问题(文章)或话题, 自定义在head中输出一个js代码  这个功能实现复杂与否 如果很复杂  就不打算弄了
已邀请:

fesiong - WeCenter第三方技术支持

赞同来自: 张大腿

是针对单篇问题吗?还是针对这个模块。不难。增加个字段就可以了。需要修改四个地方:
1、给问题、文章、话题表,增加一个js字段
2、在发布页面增加一个输入js的表单
3、到publish/ajax.php里面对应的地方修改,让js写入到数据库
4、在问题、文章、话题模板,调用这个js
==================================================================
下面是操作步骤
1、在数据库中执行下面三句
ALTER TABLE aws_article ADD js VARCHAR(250) NULL;
ALTER TABLE aws_question ADD js VARCHAR(250) NULL;
ALTER TABLE aws_topic ADD js VARCHAR(250) NULL;
2、打开views/default/topic/edit.tpl.htm
找到
<form id="topic_form" action="topic/ajax/edit_topic/" method="post" onsubmit="return false">
在后面添加
<h3><?php _e('JS代码'); ?>:</h3>
<div class="aw-publish-title active">
<div>
<input type="text" placeholder="<?php _e('JS代码'); ?>..." name="js" value="<?php echo $this->topic_info['js']; ?>" class="form-control" />
</div>
</div>
打开views/default/publish/index.tpl.htm,找到
<!-- end 问题标题 -->
在后面插入
<h3><?php _e('JS代码'); ?>:</h3>
<div class="aw-publish-title active">
<div>
<input type="text" placeholder="<?php _e('JS代码'); ?>..." name="js" value="<?php echo $this->question_info['js']; ?>" class="form-control" />
</div>
</div>
打开views/default/publish/article.tpl.htm,找到
<h3><?php _e('JS代码'); ?>:</h3>
<div class="aw-publish-title active">
<div>
<input type="text" placeholder="<?php _e('JS代码'); ?>..." name="js" value="<?php echo $this->article_info['js']; ?>" class="form-control" />
</div>
</div>
3、打开app/topic/ajax.php,找到
$this->model('topic')->update_topic($this->user_id, $_POST['topic_id'], null, $_POST['topic_description']);
在后面加入
$this->model('topic')->update('topic', array('js' => $_POST['js']), "topic_id = " . intval($_POST['topic_id']));
打开app/publish/ajax.php,找到
$article_id = $this->model('publish')->publish_article($_POST['title'], $_POST['message'], $this->user_id, $_POST['topics'], $_POST['category_id'], $_POST['attach_access_key'], $this->user_info['permission']['create_topic']);
在后面插入
if($_POST['js']){
$this->model('publish')->update('article', array('js' => $_POST['js']), "id = " . intval($article_id));
}
找到
$this->model('article')->update_article($article_info['id'], $this->user_id, $_POST['title'], $_POST['message'], $_POST['topics'], $_POST['category_id'], $this->user_info['permission']['create_topic']);
在后面插入
if($_POST['js']){
$this->model('publish')->update('article', array('js' => $_POST['js']), "id = " . intval($article_info['id']));
}
​找到
$question_id = $this->model('publish')->publish_question($_POST['question_content'], $_POST['question_detail'], $_POST['category_id'], $this->user_id, $_POST['topics'], $_POST['anonymous'], $_POST['attach_access_key'], $_POST['ask_user_id'], $this->user_info['permission']['create_topic']);
在后面添加
if($_POST['js']){
$this->model('publish')->update('question', array('js' => $_POST['js']), "question_id = " . intval($question_id));
}
找到
$this->model('question')->update_question($question_info['question_id'], $_POST['question_content'], $_POST['question_detail'], $this->user_id, $IS_MODIFY_VERIFIED, $_POST['modify_reason'], $question_info['anonymous'], $_POST['category_id']);
后面添加
if($_POST['js']){
$this->model('publish')->update('question', array('js' => $_POST['js']), "question_id = " . intval($question_info['question_id']));
}
4、打开views/default/topic/index.tpl.htm,在第二行插入
<?php echo $this->topic_info['js']; ?>

打开views/default/article/index.tpl.htm,在第二行插入
<?php echo $this->article_info['js']; ?>

打开views/default/question/index.tpl.htm,在第二行插入
<?php echo $this->question_info['js']; ?>


 
如需限制值给管理员用,那么需要加入下面代码
<?php if ($this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator']) { ?>

//这是代码

<?php } ?>

至此,已经结束

要回复问题请先登录注册