将数据评论的功能修改为ajax评论
This commit is contained in:
parent
55bcb51e46
commit
098b250fbf
|
@ -607,63 +607,98 @@ class DataController extends Zend_Controller_Action
|
|||
//数据附件
|
||||
$sql = $this->db->quoteInto("select m.id,a.realname from mdattach m left join attachments a on m.id=a.id where m.uuid=?",$uuid);
|
||||
$this->view->attachments = $this->db->fetchAll($sql);
|
||||
//数据评论
|
||||
$sql="select * from comments where uuid=? order by id desc";
|
||||
$this->view->comments=$this->db->fetchAll($sql,array($uuid));
|
||||
$user=Zend_Auth::getInstance()->getIdentity();
|
||||
$commentForm=new CommentForm();
|
||||
$formdata['uuid']=$uuid;
|
||||
$formdata['uid']=0;//用户ID,默认为0,即未登录用户
|
||||
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||||
if ($this->_request->isPost()) {
|
||||
include_once("bcspamblock.php");
|
||||
$formdata=$this->_request->getPost();
|
||||
if (bcspamblock_verify() && $commentForm->isValid($formdata)) {
|
||||
$sql="insert into comments (userid,uuid,author,email,url,ip,content,agent,type) values(?,?,?,?,?,?,?,?,?)";
|
||||
$agent=$this->_request->getHeader('User-Agent');
|
||||
$ip=$this->_request->getServer('REMOTE_ADDR');
|
||||
$type='comment';
|
||||
$stripper = new Zend_Filter_StripTags('strong');//剔除特殊字符HTML
|
||||
$content=$stripper->filter($formdata['content']);
|
||||
$author=$stripper->filter($formdata['author']);
|
||||
$this->db->query($sql,array($formdata['uid'],$formdata['uuid'],$author,$formdata['email'],$formdata['url'],$ip,$content,$agent,$type));
|
||||
$patt = array();
|
||||
$patt['user'] = $author;
|
||||
$patt['uuid'] = $formdata['uuid'];
|
||||
$patt['title']= $this->view->metadata->title;
|
||||
$patt['content']= $content;
|
||||
|
||||
$title = "收到新数据评论";
|
||||
$msg = "用户".$user->username."对元数据《".$patt['title']."》进行了评论,<a href=\"/admin/data/comment\">点击查看</a>";
|
||||
include_once("message.php");
|
||||
message::post($this->db,0,-1,$title,$msg);
|
||||
|
||||
$mailtp=new EmailText($this->db,"data-comment-note",$patt);
|
||||
$mail=new WestdcMailer($this->view->config->smtp);
|
||||
$mail->setBodyText($mailtp->getBody());
|
||||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||||
$mail->addTo($this->view->config->service->email);
|
||||
$mail->setSubject($mailtp->getSubject());
|
||||
$mail->send();
|
||||
$formdata['content']='';
|
||||
}
|
||||
} elseif ($user) {
|
||||
$formdata['uid']=$user->id;
|
||||
$formdata['author']=$user->username;
|
||||
$formdata['email']=$user->email;
|
||||
}
|
||||
$commentForm->populate($formdata);
|
||||
$this->view->commentForm=$commentForm;
|
||||
|
||||
//自动跳转
|
||||
$sql="select s.* from datasource d left join source s on d.sourceid=s.id where d.uuid=?";
|
||||
$row=$this->db->fetchRow($this->db->quoteInto($sql,$uuid));
|
||||
$jump=(int)$this->_request->getParam('jump');
|
||||
if (empty($jump)) $jump=1;//默认跳转
|
||||
if (@$row->has_pages && ($jump!=0))
|
||||
{
|
||||
{
|
||||
$this->_helper->viewRenderer($row->code.'/view',null,true);
|
||||
}
|
||||
}
|
||||
|
||||
function replace($string){
|
||||
$patterns = array("/\"/i","/\'/i");
|
||||
$replacements = array("“","‘");
|
||||
ksort($patterns);
|
||||
ksort($replacements);
|
||||
return preg_replace($patterns, $replacements, $string);
|
||||
}
|
||||
|
||||
function postcommentAction(){
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
try{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if($auth->hasIdentity())
|
||||
{
|
||||
$user = $auth->getIdentity();
|
||||
$userid = $user->id;
|
||||
}else
|
||||
{
|
||||
$userid=0;
|
||||
}
|
||||
|
||||
$author = mb_substr($this->replace(trim($this->_request->getParam('author'))),0,30,'UTF-8');
|
||||
$email = mb_substr($this->replace(trim($this->_request->getParam('email'))),0,60,'UTF-8');
|
||||
$url = mb_substr($this->replace(trim($this->_request->getParam('url'))),0,60,'UTF-8');
|
||||
$content = $this->replace(trim($this->_request->getParam('content')));
|
||||
|
||||
if(strlen($author)<3) exit("姓名长度不得少于2个汉字 :)");
|
||||
|
||||
if(strlen($email)<4) exit("Email长度太短,请填写正确的Email :)");
|
||||
|
||||
if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email))
|
||||
{
|
||||
echo "Email格式不正确";
|
||||
exit();
|
||||
}
|
||||
|
||||
if(strlen($content)<5) exit("评论长度不得少于3个汉字 :)");
|
||||
|
||||
$uuid = trim($this->_request->getParam('uuid'));
|
||||
|
||||
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
||||
{
|
||||
echo "参数错误";
|
||||
exit();
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'uuid' => $uuid,
|
||||
'uid' => $userid,
|
||||
'author' => $author,
|
||||
'email' => $email,
|
||||
'url' => $url,
|
||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
||||
'content' => $content,
|
||||
'agent' => $_SERVER['HTTP_USER_AGENT'],
|
||||
'type' => 'comment'
|
||||
);
|
||||
|
||||
$sql = "INSERT INTO comments (author,email,url,ip,content,agent,type,uuid,userid) VALUES (?,?,?,?,?,?,?,?,?)";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$exec = $sth->execute(array($data['author'],$data['email'],$data['url'],$data['ip'],$data['content'],$data['agent'],$data['type'],$data['uuid'],$data['uid']));
|
||||
|
||||
if($exec)
|
||||
{
|
||||
$msg = "用户".$user->username."对元数据《".$this->replace(trim($this->_request->getParam('mdtitle')))."》进行了评论,<a href=\"/admin/data/comment\">点击查看</a>";
|
||||
include_once("message.php");
|
||||
message::post($this->db,0,-1,"收到新数据评论",$msg);
|
||||
echo "评论成功<script>$('#reset').click();</script>";
|
||||
exit();
|
||||
}else
|
||||
{
|
||||
echo "评论失败,请重试 :)";
|
||||
exit();
|
||||
}
|
||||
}catch(Exception $e){
|
||||
echo "出错了,请稍后再试";
|
||||
exit();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 数据评论,根据UUID读取
|
||||
*/
|
||||
|
|
|
@ -146,7 +146,7 @@ endforeach;
|
|||
</div>
|
||||
|
||||
</div>
|
||||
<div id="left">
|
||||
<div id="left">
|
||||
<div id="ImageViewer"><a class="colorbox" title="<?php echo $md->title; ?>" href="/service/bigthumb/uuid/<?php echo $md->uuid; ?>"><img src="/service/thumb/uuid/<?php echo $md->uuid;?>"/></a></div>
|
||||
<div id="abstract">
|
||||
<p>
|
||||
|
@ -257,7 +257,31 @@ echo '</li>';
|
|||
<div id="allcomments">
|
||||
<div id="loading"><img src="/images/loading.gif" />评论加载中</div>
|
||||
</div>
|
||||
<?php echo $this->commentForm; ?>
|
||||
<form id="postcommentform">
|
||||
<p>
|
||||
<label class="required" style="background:none;">姓名</label>
|
||||
<input type="text" name="author" />
|
||||
</p>
|
||||
<p>
|
||||
<label class="required" style="background:none;">EMAIL</label>
|
||||
<input type="text" name="email" />
|
||||
</p>
|
||||
<p>
|
||||
<label>WEBSITE</label>
|
||||
<input type="text" name="url" />
|
||||
</p>
|
||||
<p>
|
||||
<label class="required" style="background:none;">内容</label>
|
||||
<textarea name="content" class="medium half"></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<label> </label>
|
||||
<input type="hidden" name="mdtitle" value="<?php echo $md->title;?>" />
|
||||
<input type="hidden" name="uuid" value="<?php echo $md->uuid;?>" />
|
||||
<a class="btn btn-green" id="postcomment" href="javascript:;" onclick="postcomment();">提交</a><button type="reset" id="reset" class="btn">重置</button><span id="returninfo"></span>
|
||||
</p>
|
||||
</form>
|
||||
<div id="infobox"></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -275,23 +299,23 @@ echo '</li>';
|
|||
|
||||
<div id="todownload" style="display:none;">
|
||||
<div class="closeox"><a href="javascript:void(0);" onclick="$('#todownload').hide()">[关闭]</a></div>
|
||||
<div id="returninfo" style="">
|
||||
<div id="formcontent" style="">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(document).ready(function(){$(".colorbox").colorbox({photo:"true"});});
|
||||
$(window).bind("load", function() { var timeout = setTimeout(function() { initLoader(); }, 100);});
|
||||
//$(window).bind("load", function() { var timeout = setTimeout(function() { gmaploaded(); }, 1000);});
|
||||
function loadMaps() {
|
||||
google.load("maps", "2", {"callback" : gmaploaded,"base_domain": "ditu.google.cn"});
|
||||
}
|
||||
|
||||
function initLoader() {
|
||||
var script = document.createElement("script");
|
||||
script.src = "https://www.google.com/jsapi?key=<?php echo $this->config->google->maps->api; ?>&callback=loadMaps";
|
||||
script.type = "text/javascript";
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(document).ready(function(){$(".colorbox").colorbox({photo:"true"});});
|
||||
$(window).bind("load", function() { var timeout = setTimeout(function() { initLoader(); }, 100);});
|
||||
//$(window).bind("load", function() { var timeout = setTimeout(function() { gmaploaded(); }, 1000);});
|
||||
function loadMaps() {
|
||||
google.load("maps", "2", {"callback" : gmaploaded,"base_domain": "ditu.google.cn"});
|
||||
}
|
||||
|
||||
function initLoader() {
|
||||
var script = document.createElement("script");
|
||||
script.src = "https://www.google.com/jsapi?key=<?php echo $this->config->google->maps->api; ?>&callback=loadMaps";
|
||||
script.type = "text/javascript";
|
||||
document.getElementsByTagName("head")[0].appendChild(script);
|
||||
}
|
||||
//ajax download
|
||||
function todownload(ft)
|
||||
|
@ -303,14 +327,17 @@ function todownload(ft)
|
|||
url:url,
|
||||
data:date,
|
||||
success:function(html){
|
||||
$('#returninfo').html(html);
|
||||
$('#formcontent').html(html);
|
||||
},
|
||||
beforeSend:function(){
|
||||
$('#returninfo').html('<img src="/images/11887177066.gif" />');
|
||||
$('#formcontent').html('<img src="/images/11887177066.gif" />');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//ajax comment
|
||||
ajaxpage(0);
|
||||
|
||||
function ajaxpage(page){
|
||||
var url = "/data/comment/uuid/<?= $md->uuid; ?>";
|
||||
data='page='+page;
|
||||
|
@ -321,7 +348,28 @@ function ajaxpage(page){
|
|||
success:function(html){$('#allcomments').html(html);},
|
||||
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');}
|
||||
});
|
||||
};ajaxpage(0);
|
||||
};
|
||||
function postcomment(){
|
||||
var url="/data/postcomment";
|
||||
var date = $('#postcommentform').serialize();
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':url,
|
||||
'data':date,
|
||||
'success':function(html){
|
||||
$('#postcomment').html('提交');
|
||||
setTimeout("$('#postcomment').removeAttr('disabled');",3000);
|
||||
$('#returninfo').html(html);
|
||||
ajaxpage(0);
|
||||
},
|
||||
'beforeSend':function(){
|
||||
$('#postcomment').attr('disabled','disabled');
|
||||
$('#postcomment').html('<img src="/images/11887177066.gif" />正在提交...');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getFileList(){
|
||||
var tw = ($(window).width() - $('#window-outter').width())/2;
|
||||
$('#window-inner').css('min-height','450px');
|
||||
|
@ -375,9 +423,9 @@ function getSubFileList(uuid,id,depth){
|
|||
$('#span_'+id).html('-');
|
||||
}
|
||||
});
|
||||
}
|
||||
function gmaploaded()
|
||||
{
|
||||
}
|
||||
function gmaploaded()
|
||||
{
|
||||
//google map
|
||||
var map = new GMap2(document.getElementById("watermap"));
|
||||
var plotbounds=new GLatLngBounds(new GLatLng(<?= $md->south; ?>,<?= $md->west; ?>),new GLatLng(<?= $md->north; ?>,<?= $md->east; ?>));
|
||||
|
@ -402,7 +450,7 @@ zoomlevel--;
|
|||
new GLatLng(<?= $md->north; ?>,<?= $md->west; ?>)
|
||||
],"#f33f00",5,1,"#ff0000",0.2);
|
||||
map.addOverlay(polygon);
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
}
|
||||
</script>
|
||||
<?php else: ?>
|
||||
|
|
Loading…
Reference in New Issue