php专区

 首页 > php专区 > PHP应用 > CMS建站 > phpmps调用discuz x方法 - Discuz

phpmps调用discuz x方法 - Discuz

分享到:
【字体:
导读:
          本贴介绍phpmps调用discuz x方法(非JS),也就是调用静态的帖子到,phpmps首页,这对seo非常必要。phpmps是一款非常实用的php分类信息开源系统...

phpmps调用discuz x方法

本贴介绍phpmps调用discuz x方法(非JS),也就是调用静态的帖子到,phpmps首页,这对seo非常必要。

phpmps是一款非常实用的php分类信息开源系统,前些天我给一个网站采用了该系统,在首页调用discuz x2.5论坛内容,但是一直没有找到方法,phpmps官方的论坛人少之又少,在此写个phpmps调用discuz x方法,该方法同样适用于ecshop等其他开源程序的调用,下面不多说废话了,入正题:

具体方法:

新建一个文本文件,把以下代码保存在文本文件中,然后把它重命名为cron_makehtml_daily.php,即php文件,然后通过ftp工具把cron_makehtml_daily.php上传到论坛目录下的/source/include/cron/目录中.

  1. if(!defined('IN_DISCUZ')) { 
  2.  
  3. exit('Access Denied'); 
  4.  
  5.  
  6. $newhtml = ''
  7.  
  8. $query = DB::query("SELECT t.*, f.name FROM bbs_forum_thread t, bbs_forum_forum f WHERE t.fid=f.fid and f.fid IN('2','36','37','39','40','42') ORDER BY t.dateline DESC LIMIT 0, 10");  //这里要修改你自己想要调用的版块ID 
  9.  
  10. while($new = DB::fetch($query)) { 
  11.  
  12. $newsubject = cutstr($new['subject'],48); 
  13.  
  14. $newurl = 'http://www.100de.com.cn/bbs/thread-'.$new['tid'].'-1-1.html'
  15.  
  16. $newhtml .= '
  17. .$newurl.'">'.$newsubject.'
  18. '
  19.  
  20. }

    $newhtml = convert_data($newhtml); 

  21.  
  22. writehtml('newhtml.htm'$newhtml); 
  23.  
  24. //写入html文件 
  25.  
  26. function writehtml($file$html) { 
  27.  
  28.         global $timestamp
  29.  
  30.         $yearmonth = gmdate('Ym'$timestamp + 8 * 3600); 
  31.  
  32.         $logdir = DISCUZ_ROOT.'./data/cache/'
  33.  
  34.         $logfile = $logdir.$file
  35.  
  36.         if($fp = @fopen($logfile'w')) { 
  37.  
  38.                 @flock($fp, 2); 
  39.  
  40.                 fwrite($fp"$html"); 
  41.  
  42.                 fclose($fp); 
  43.  
  44.         } 
  45.  
  46.  
  47. function convert_data($data) { 
  48.  
  49.         include_once DISCUZ_ROOT.'./source/class/class_chinese.php'
  50.  
  51.         $c = new Chinese('utf8','gbk'); 
  52.  
  53.         $data = $c->Convert($data); 
  54.  
  55.         return $data
  56.  
  57. ?> 

上面是夫唯老师提供给我的代码,因为我本身的服务器环境是utf-8的,所以我注释了2段代码,才显示正常.

第一段代码,是编码转换:

//$newhtml = convert_data($newhtml);

第二段代码,编码转换的方法

然后登陆论坛后台管理中心,工具->计划任务,增加一个新的计划任务名“输出html”,名字可以自己取,然后点击这个任务的“编辑”,在“任务脚本”里面输入:cron_makehtml_daily.php,其他更新时间设置,自己选择,也可以保持默认,点击“提交”.

然后,通过这个地址http://www.phpfensi.com.cn/bbs/data/cache/newhtml.htm,可以获得html格式的论坛最新10个帖子,如果显示乱码,切换到UTF-8编码下查看.

在phpmps的模板文件需要调用的地方加入如下代码:

  1.  
  2.   $data=array('foo'=>'bar'); 
  3.  
  4.   $data=http_build_query($data); 
  5.  
  6.   $opts=array
  7.  
  8.     'http'=>array
  9.  
  10.    'method'=>'POST'
  11.  
  12.    'header'=>"Content-type: application/x-www-form-urlencodedrn"
  13.  
  14.     "Content-Length: ".strlen($data)."rn"
  15.  
  16.   'content'=>$data 
  17.  
  18.   ), 
  19.  
  20.   ); 
  21.  
  22. $context=stream_context_create($opts); 
  23.  
  24. $html=file_get_contents('http://www.phpfensi.com.cn/bbs/data/cache/newhtml.htm',false,$context); 
  25.  
  26. echo$html
  27.  
  28. ?> 

OK,可以了,没调用出来的同学,清理下phpmps和discuz的缓存。

分享到:
Discuz X3论坛如何清除“无效楼层,该帖...
Discuz X3论坛如何清除“无效楼层,该帖已经被删除” 相信人气好、管理好的Discuz论坛站长都有删帖或者屏蔽某个经常打广告的ID或者发帖机顶贴的留言,总之这些都是论坛站长们经常会遇到,并且要处理的事情,不过您会发现删除完留言之后发现楼数还是存在的,只是在那一楼的内容显示的是“无效楼层...
Discuz!X2.5和UCenter_1.6.0 - Discuz
Discuz!X2.5和UCenter_1.6.0 操作系统:CentOS5.5_x64 一、依赖包的安装 yum -y install gcc gcc-c++ mysql mysql-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 b...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……