帝国CMS新闻模型转换成文章模型的方法

新闻模型与文章模型的区别

1.新闻系统模型的内容(newstext)是存放数据库的;而文章系统模型的内容(newstext)是存放于文本文件。对于数据量比较大的,推荐使用文章系统模型。 

2.新闻系统模型支持内容(newstext)搜索;而文章系统模型不支持内容(newstext)搜索。

把帝国CMS新闻模型转换成文章模型的方法:

1、数据备份

非常重要。万一在转换过程中出现意外,确保数据安全。

2、数据库转换

将以下代码保存为一个php文件,文件编码格式与你网站编码相同,代码中的参数设置部分按照实际情况来填写。

PHP

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);

@set_time_limit(1000);

//********************* 参数设置开始 *********************

$newstb="gushi"; //需要转换的数据表

$cf='newstext';//需要转换的字段名

$fa=1;//字段位置,0为主表,1为副表

$changeline=50; //每组转换数

//********************* 参数设置结束 *********************

if($_GET['tochange']==1)

{

    include("../class/connect.php");

    include("../class/db_sql.php");

    include("../class/functions.php");

    $link=db_connect();

    $empire=new mysqlquery();

    dp_ChangeNewsToArticle($_GET['start']);

}

//开始转换

function dp_ChangeNewsToArticle($start=0){

    global $empire,$newstb,$cf,$fa,$changeline,$dbtbpre;

    $start=(int)$start;

    if($start==0){

        $ckist=$empire->fetch1("select fid,savetxt from {$dbtbpre}enewsf where tbname='$newstb' and f='$cf' limit 1");

        if(!$ckist['fid']){

            exit("参数设置错误");

        }

        if(!$ckist['savetxt']){

            //字段表

            $empire->query("update {$dbtbpre}enewsf set savetxt=1 where tbname='$newstb' and f='$cf' limit 1");

            //组合存文本

            TogSaveTxtF(1);

            //更新缓存

            GetConfig(1);

        }

    }

    $b=0;

    $tbname=$fa?$newstb."_data_1":$newstb;

    $sql=$empire->query("select id,classid,".$cf." from {$dbtbpre}ecms_".$tbname." where id>$start order by id limit ".$changeline);

    while($r=$empire->fetch($sql)){

        $b=1;

        $newid=$r['id'];

        $newstext=dp_ReturnChangeNewstextUrl($r[$cf],$r['id']);

        $empire->query("update {$dbtbpre}ecms_".$tbname." set ".$cf."='$newstext' where id='$newid' limit 1");

    }

    if($b==0)

    {

        echo"恭喜您!转换完毕。";

        exit();

    }

    echo"一组数据转换完毕,正进入下一组 (<font color=red><b>".$newid."</b></font>)......<script>self.location.href='index.php?tochange=1&start=$newid';</script>";

    exit();

}

//返回内容地址

function dp_ReturnChangeNewstextUrl($value,$id){

    global $public_r,$newstb,$cf;

    //存放文本

    if(strstr($public_r['savetxtf'],",".$newstb.".".$cf.","))

    {

        $truetime=time();

        //建立目录

        $thetxtfile=GetFileMd5().$id;

        $truevalue=MkDirTxtFile(date("Y/md",$truetime),$thetxtfile);

        //写放文件

        EditTxtFieldText($truevalue,$value);

        $value=$truevalue;

    }

    else{

        exit("参数设置错误");

    }

    return $value;

}

?>

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);

@set_time_limit(1000);

//********************* 参数设置开始 *********************

$newstb="gushi"; //需要转换的数据表

$cf='newstext';//需要转换的字段名

$fa=1;//字段位置,0为主表,1为副表

$changeline=50; //每组转换数

//********************* 参数设置结束 *********************

if($_GET['tochange']==1)

{

    include("../class/connect.php");

    include("../class/db_sql.php");

    include("../class/functions.php");

    $link=db_connect();

    $empire=new mysqlquery();

    dp_ChangeNewsToArticle($_GET['start']);

}

//开始转换

function dp_ChangeNewsToArticle($start=0){

    global $empire,$newstb,$cf,$fa,$changeline,$dbtbpre;

    $start=(int)$start;

    if($start==0){

        $ckist=$empire->fetch1("select fid,savetxt from {$dbtbpre}enewsf where tbname='$newstb' and f='$cf' limit 1");

        if(!$ckist['fid']){

            exit("参数设置错误");

        }

        if(!$ckist['savetxt']){

            //字段表

            $empire->query("update {$dbtbpre}enewsf set savetxt=1 where tbname='$newstb' and f='$cf' limit 1");

            //组合存文本

            TogSaveTxtF(1);

            //更新缓存

            GetConfig(1);

        }

    }

    $b=0;

    $tbname=$fa?$newstb."_data_1":$newstb;

    $sql=$empire->query("select id,classid,".$cf." from {$dbtbpre}ecms_".$tbname." where id>$start order by id limit ".$changeline);

    while($r=$empire->fetch($sql)){

        $b=1;

        $newid=$r['id'];

        $newstext=dp_ReturnChangeNewstextUrl($r[$cf],$r['id']);

        $empire->query("update {$dbtbpre}ecms_".$tbname." set ".$cf."='$newstext' where id='$newid' limit 1");

    }

    if($b==0)

    {

        echo"恭喜您!转换完毕。";

        exit();

    }

    echo"一组数据转换完毕,正进入下一组 (<font color=red><b>".$newid."</b></font>)......<script>self.location.href='index.php?tochange=1&start=$newid';</script>";

    exit();

}

//返回内容地址

function dp_ReturnChangeNewstextUrl($value,$id){

    global $public_r,$newstb,$cf;

    //存放文本

    if(strstr($public_r['savetxtf'],",".$newstb.".".$cf.","))

    {

        $truetime=time();

        //建立目录

        $thetxtfile=GetFileMd5().$id;

        $truevalue=MkDirTxtFile(date("Y/md",$truetime),$thetxtfile);

        //写放文件

        EditTxtFieldText($truevalue,$value);

        $value=$truevalue;

    }

    else{

        exit("参数设置错误");

    }

    return $value;

}

?>

Markup

<html>

<head>

<title>新闻模型转文章模型程序</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<style>

a:link     { COLOR: #000000; TEXT-DECORATION: none }

a:visited   { COLOR: #000000 ; TEXT-DECORATION: none }

a:active   { COLOR: #000000 ; TEXT-DECORATION: underline }

a:hover    { COLOR: #000000 ; TEXT-DECORATION:underline }

.home_top { border-top:2px solid #4798ED; }

.home_path { background:#4798ED; padding-right:10px; color:#F0F0F0; font-size: 11px; }

td, th, caption { font-family:  "宋体"; font-size: 12px; color:#000000;  LINE-HEIGHT: 165%; }

.hrLine{MARGIN: 0px 0px; BORDER-BOTTOM: #807d76 1px dotted;}

</style>

</head>

<body>

  <p><br>

  <br>

  </p>

  <form method="get" action="index.php" onsubmit="return confirm('确认要执行?');">

  <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#0472BC">

    <tr>

      <td height="25"><div align="center"><font color="#FFFFFF" size="3"><strong>新闻模型转文章模型程序</strong></font></div></td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td height="50">

        <div align="center">

          <input type=submit name=ok value="点击开始转换">

          <input type=hidden name="tochange" value=1>

        </div></td>

    </tr>

  </table>

</form>

</body>

</html>

<html>

<head>

<title>新闻模型转文章模型程序</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<style>

a:link     { COLOR: #000000; TEXT-DECORATION: none }

a:visited   { COLOR: #000000 ; TEXT-DECORATION: none }

a:active   { COLOR: #000000 ; TEXT-DECORATION: underline }

a:hover    { COLOR: #000000 ; TEXT-DECORATION:underline }

.home_top { border-top:2px solid #4798ED; }

.home_path { background:#4798ED; padding-right:10px; color:#F0F0F0; font-size: 11px; }

td, th, caption { font-family:  "宋体"; font-size: 12px; color:#000000;  LINE-HEIGHT: 165%; }

.hrLine{MARGIN: 0px 0px; BORDER-BOTTOM: #807d76 1px dotted;}

</style>

</head>

<body>

  <p><br>

  <br>

  </p>

  <form method="get" action="index.php" onsubmit="return confirm('确认要执行?');">

  <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#0472BC">

    <tr>

      <td height="25"><div align="center"><font color="#FFFFFF" size="3"><strong>新闻模型转文章模型程序</strong></font></div></td>

    </tr>

    <tr bgcolor="#FFFFFF">

      <td height="50">

        <div align="center">

          <input type=submit name=ok value="点击开始转换">

          <input type=hidden name="tochange" value=1>

        </div></td>

    </tr>

  </table>

</form>

</body>

</html>

假设你为此新建了一个名为 zh.php 的文件,那么将此文件放到 e/update/  文件夹中。那么你这时在浏览器中执行以下网址:

https://www.******.com/e/update/zh.php?tochange=1

此程序会分组转换数据。

请注意:

(1)不能重复转换,否则数据丢失。

(2)转换完之后请立即在服务器上删除此文件。

(3)此程序适用于帝国cms7.0及后续版本。

3、模板修改

如果你在之前模板中用php代码调用过被转换的字段,则此时需要用函数 GetTxtFieldText 来读取。

例如,在之前你调用newstext用代码:

<?=$navinfor['newstext']?>

newstext转换成存文本之后必调用代码是:

<?=GetTxtFieldText($navinfor['newstext'])?>

You may also like

  • 很赞同的一个普通人活法的说法
  • 121.jpg, Jan 2024 英国开个公司具体摘录
  • 天龙八部的人生,其实也是作者世界的体现
  • 社会中的十个潜规则,很有道理
  • giffgaff配合5元随身wifi一行代码实现每6个月自动发送一次短信
  • 目前很多省份的社保买了很不划算,那么怎么买才划算呢?
  • 五胡乱华135年历史,最近学习了解这里,摘录于此
  • liqiu.jpg, Aug 2023 今日立秋,没有秋后的第一杯奶茶,摘录古人相关立秋的100首诗词