18038435860

JTBC_PHP 3.0.1.6版本增加文章定时发布功能(二)

时间:2018-11-30 23:19:19 点击:624 来源:易速网络

1、数据库jtbc_news增加字段n_timing,类型DATETIME,注释{"fieldType":"text"}
 
<item>
<name><![CDATA[timing]]></name>
<zh-cn><![CDATA[定时]]></zh-cn>
</item>
 
 
$nowTime = base::getDateTime();
    if ($category == 0){
      $sqlstr = "select * from jtbc_news where n_delete=0 and n_publish=1 and n_timing< '" .$nowTime."' order by n_time desc";
    } else {
      $sqlstr = "select * from jtbc_news where n_delete=0 and n_publish=1 and n_timing< '" .$nowTime."' and n_category = '" .$category."' order by n_time desc";
    }
    $pagi = new pagi();
    $rsAry = $pagi -> getDataAry($page, $pagesize, $sqlstr);
 
~~~~~~~~~~~~~~~~~~~~~~~~~
4、/* $dal -> orderBy('time', 'desc');
$pagi = new pagi($dal);
$rsAry = $pagi -> getDataAry($page, $pagesize);*/
    注释掉这3行
 
5、设置发布时间,定时发布时间格式2018-11-09 10:45:28,点发布开关到绿色发布状态,然后提交。

 

1.jtbc.push.js放至/console/common/assets/js
2.push.inc.php放至/console/common/incfiles
3.在/news/template/manage.jtbc中查找
<name><![CDATA[list]]></name>节点,注意是[list]节点,在第3个<default><![CDATA[<nav genre="{$=$genre}"><span>{$-account-nav}{$=universal\category::getCategoryNavByID($getPara('genre'), '{$-lang}', '{$-nav-category}')}</span></nav>
后添加<script type="text/javascript" src="{$=$assetspath}/js/jtbc.push.js"></script>

 

如果你在其他地方调用新闻标题列表,比如首页,就加上一句SQL

比如这个<jtbc $function="transfer" $parameter="genre=news;type=new;limit=6;osql= and n_time<now()">

还有这个{$=transfer('genre=news;category=3;type=new;limit=24;osql= and n_time<now();baseurl=./;tpl=news_list')}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jtbc.push.js代码如下

$(document).ready(function(){
var s = jQueryAjaxPost("2");
});
function jQueryAjaxPost(pushData) {
var return_data = "";
$.ajax({
type: "POST",
dataType: "json",
url: "common/incfiles/push.inc.php",
data: pushData,
async: false,
success: function(data, status) {
if(status == "success") {
return_data = data;
} else {
return_data = "error";
}
}
});
return return_data;
}

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

push.inc.php代码如下

<?php
include_once ("../../../common/incfiles/const.php");
$r = array();
@$db = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_errno()) {
echo json_encode("sorry,the conntect had some wrongs");
exit ;
}
$read = "select n_id,n_time,n_timing from jtbc_news where n_id=(select max(n_id) from jtbc_news)";
$result = mysqli_query($db, $read);
$rownumber = mysqli_num_rows($result);
for ($i = 0; $i < $rownumber; $i++) {
$row = mysqli_fetch_assoc($result);
array_push($r, $row['n_id'], $row['n_time'],$row['n_timing']);
}
if(($r[2]!=null)&&($r[1]!=$r[2])){
$up="update jtbc_news set n_time='$r[2]' where n_id='$r[0]'";
mysqli_query($db, $up);
}
mysqli_close($db);
echo json_encode("ok");
?>

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~