百独托管7500 紫田网络超高转化播放器收cps[推荐]速盾CDN 免实名免备防屏蔽阿里云 爆款特卖9.9元封顶提升alexa、IP流量7Q5团队
【腾讯云】中小企福利专场【腾讯云】多款产品1折起高防 随时退换 好耶数据小飞国外网赚带你月入万元炎黄网络4H4G10M 99每月
香港带宽CN2/美国站群优惠中客数据中心 服务器租用联盟系统移动广告平台 中易企业专场腾讯云服务器2.5折九九数据 工信部正规资质
腾讯云新用户大礼包代金券高价收cpa注册量高价展示【腾讯云】2核2G/9.93起租服务器找45互联 随时退换阿里云 短信服务 验证秒达

[其它内容] BT种子信息插件 For Discuz 5.0 [复制链接]
查看:5431 | 回复:11

3

主题

1万

帖子

1万

积分

落伍者(四季发财)

无*妻*徒刑

Rank: 4

贡献
0
鲜花
6
注册时间
2004-4-12
发表于 2007-2-3 10:16:58 | |阅读模式 来自 中国广东东莞
请版主来加精。。 DZ貌似还没有bt信息插件哦。

插件名称: BT种子信息插件
适用版本: Discuz 5.0
插件作者: blue2004
更新日期: 2007-2-3
安装难度:        easy
插件功能: 发帖的时候使用disuczcode标签[bt]http://127.0.0.1/test.torrent[/bt]
包括识别远程路径的文件,自动分析种子的信息,并保存于数据库中。
整个插件代码函数化,调用非常方便,还可以整合在其他php论坛中使用。

数据库升级: None

缺陷和不足:
1.发帖时候如果同时出现两个以上的[bt]将只能解释第一个,
但一直没写出其中的正则替换多个标签。
2.采用了远程读取和mb_string或iconv及对照表形式进行了UTF-8的转换
效率可能有点问题,而且很少有虚拟主机的伺服器能支持mb_string或iconv。
3.水平有限,代码很凌乱,参考了不少程序的函数,在此不说了,看你能看出几个。


打开discuzcode.func.php,在最后一行(大概320)后添加下列代码:

  1. /*-------------------torrent plug----------------
  2. author:blue2004
  3. QQ:80392625
  4. HomePage:http://www.pearphp.com/
  5. Email:pearphp#gmail.com
  6. Date:2007-2-3
  7. ------------------------------------------------*/

  8.   function convert_encoding($str, $from, $to)
  9.         {
  10.                
  11.                 if (function_exists('mb_convert_encoding')) {
  12.                         $str = mb_convert_encoding($str, $to, $from);
  13.                 } elseif (function_exists('iconv')) {
  14.                         $str = iconv($from, $to, $str);
  15.                 } else {
  16.                         include_once(DISCUZ_ROOT.'./include/functions_encoding.php');
  17.                         $encode= new Encoding();
  18.                         $str = $encode->EncodeString($str, $from, $to);
  19.             }
  20.                 return $str;
  21.         }

  22.         function iif($expression, $returntrue, $returnfalse = '')
  23.         {
  24.                 return ($expression ? $returntrue : $returnfalse);
  25.         }

  26. /**
  27. * Formats a number with user's own decimal and thousands chars
  28. *
  29. * @param        mixed        Number to be formatted: integer / 8MB / 16 GB / 6.0 KB / 3M / 5K / ETC
  30. * @param        integer        Number of decimal places to display
  31. * @param        boolean        Special case for byte-based numbers
  32. *
  33. * @return        mixed        The formatted number
  34. */
  35. function vb_number_format($number, $decimals = 0, $bytesize = false)
  36. {
  37.         $type = '';
  38.         if (empty($number))
  39.         {
  40.                 return 0;
  41.         }
  42.         else if (preg_match('#^(\d+(?:\.\d+)?)(?>\s*)([mkg])b?$#i', trim($number), $matches))
  43.         {
  44.                 switch(strtolower($matches[2]))
  45.                 {
  46.                         case 'g':
  47.                                 $number = $matches[1] * 1073741824;
  48.                                 break;
  49.                         case 'm':
  50.                                 $number = $matches[1] * 1048576;
  51.                                 break;
  52.                         case 'k':
  53.                                 $number = $matches[1] * 1024;
  54.                                 break;
  55.                         default:
  56.                                 $number = $matches[1] * 1;
  57.                 }
  58.         }

  59.         if ($bytesize)
  60.         {
  61.                 if ($number >= 1073741824)
  62.                 {
  63.                         $number = $number / 1073741824;
  64.                         $decimals = 2;
  65.                         $type = "G";
  66.                 }
  67.                 else if ($number >= 1048576)
  68.                 {
  69.                         $number = $number / 1048576;
  70.                         $decimals = 2;
  71.                         $type = "MB";
  72.                 }
  73.                 else if ($number >= 1024)
  74.                 {
  75.                         $number = $number / 1024;
  76.                         $decimals = 1;
  77.                         $type = "KB";
  78.                 }
  79.                 else
  80.                 {
  81.                         $decimals = 0;
  82.                         $type = " bytes";
  83.                 }
  84.         }
  85.         return str_replace('_', ' ', number_format($number, $decimals)) . $type;
  86. }

  87.         //        {{{        bt UBB()

  88.         /**
  89.          *get bt tag
  90.          */
  91.         function tag_bt($info){
  92.                 $info = stripslashes($info);
  93.                 preg_match_all("/\[bt\](.+?)\[\/bt\]/is", $info, $matches);
  94.                 return $matches[1];
  95.         }

  96.         //        {{{        fetchContent()

  97.         /**
  98.          * Fetch the remote content.
  99.          * @param        string        url of the page
  100.          * @param        string        get the http header?
  101.          * @return        string        HTML of the page
  102.          */
  103.         function fetchContent($url, $getHeader = false)
  104.         {
  105.                 $content = "";
  106.                 if (ini_get('allow_url_fopen') && !$getHeader) {
  107.                         //ByFile
  108.                         $handle = @fopen($url,"r");
  109.                         if(!$handle){
  110.                                 return false;
  111.                         }
  112.                         while($buffer = fgets($handle, 4096)) {
  113.                           $content .= $buffer;
  114.                         }
  115.                         fclose($handle);
  116.                         return $content;
  117.                 } elseif (function_exists('curl_init')) {
  118.                         //ByCurl
  119.                         $handle = curl_init();
  120.                         curl_setopt ($handle, CURLOPT_URL, $url);
  121.                         curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 5);
  122.                         curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
  123.                         curl_setopt ($handle, CURLOPT_FOLLOWLOCATION, 0);
  124.                         if ($getHeader) {
  125.                                 curl_setopt ($handle, CURLOPT_HEADER, 1);
  126.                                 curl_setopt ($handle, CURLOPT_NOBODY, 1);
  127.                         }
  128.                         $content = curl_exec($handle);
  129.                         curl_close($handle);
  130.                         return $content;
  131.                 } elseif (function_exists('fsockopen')) {
  132.                         //BySocket
  133.                         if (!($pos = strpos($url, '://'))) {
  134.                                 return false;
  135.                         }
  136.                         $host = substr($url, $pos+3, strpos($url, '/', $pos+3) - $pos - 3);
  137.                         $uri = substr($url, strpos($url, '/', $pos+3));
  138.                         $request = "GET " . $uri . " HTTP/1.0\r\n"
  139.                                            ."Host: " . $host . "\r\n"
  140.                                            ."Accept: */*\r\n"
  141.                                            ."User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n"
  142.                                            ."\r\n";
  143.                         $handle = @fsockopen($host, 80, $errno, $errstr, 30);
  144.                         if (!$handle) {
  145.                                 return false;
  146.                         }
  147.                         @fputs($handle, $request);
  148.                         while (!feof($handle)){
  149.                                 $content .= fgets($handle, 4096);
  150.                         }
  151.                         fclose($handle);
  152.                         $separator = strpos($content, "\r\n\r\n");
  153.                         if($getHeader) {
  154.                                 if($separator === false) {
  155.                                         return false;
  156.                                 } else {
  157.                                         return substr($content, 0, $separator);
  158.                                 }
  159.                         } else {
  160.                                 if($separator === false) {
  161.                                         return $content;
  162.                                 } else {
  163.                                         return substr($content, $separator + 4);
  164.                                 }
  165.                         }
  166.                 } else {
  167.                         return false;
  168.                 }
  169.         }

  170. function info_bt($message){
  171.         $array =tag_bt($message);
  172.         if (is_array($array)) {
  173.                 #echo count($array);
  174.                 #foreach ($array as $key => $value) {
  175.                         #echo $array[$key];
  176.                         @set_time_limit(10);
  177.                         $content = fetchContent($array['0']);
  178.                         if (!empty($content)) {
  179.                                 include_once DISCUZ_ROOT.'./include/bencode.php';
  180.                                 $bencode = new BEncodeLib();
  181.                                 $torrent = $bencode->bdecode($content);
  182.                                 if (is_array($torrent)) {
  183.                                         #print_r($torrent);
  184.                                                 if (is_array($torrent['announce-list'])) {
  185.                                                         foreach ($torrent['announce-list'] as $key => $value) {
  186.                                                                 $announce .= $torrent['announce-list'][$key][0] . '\n';
  187.                                                         }
  188.                                                 } else {
  189.                                                         $announce = $torrent['announce'];
  190.                                                 }
  191.                                                         $created_by = $torrent['created by'];
  192.                                                         $creation_date =$torrent['creation date'];
  193.                                                         $encoding = $torrent['encoding'];
  194.                                                         #$codepage= $torrent['codepage'];#error
  195.                                                         $name =  convert_encoding($torrent['info']['name.utf-8'],$from="UTF-8", $to="GBK");
  196.                                                         #$length = $torrent['info']['length'];#error
  197.                                                         #$pieces =$torrent['info']['pieces'];#error
  198.                                                         $piece_length =$torrent['info']['piece length'];
  199.                                                         $publisher =convert_encoding($torrent['info']['publisher.utf-8'],$from="UTF-8", $to="GBK");
  200.                                                         $publisher_url =$torrent['info']['publisher-url.utf-8'];
  201.                                                         $bt_head ="[url=$array[0]]下载种子文件[/url]\n[b]Tracker Url:[/b]\n".$announce."[b]软件:[/b]".$created_by."\n[b]编码:[/b]".$encoding."\n[b]名称:[/b]".$name."\n[b]块长度:[/b]".$piece_length."\n[b]发布人:[/b]".$publisher."\n[b]站点:[/b]".$publisher_url."\n";
  202.                                                         #*********nodes
  203.                                                         if (is_array($torrent['nodes'])){
  204.                                                                 foreach ($torrent['nodes'] as $key => $value) {
  205.                                                                         $nodes .= $torrent['nodes'][$key][0] . ':' . $torrent['nodes'][$key][1] . "\n";
  206.                                                                 }
  207.                                                         }else{
  208.                                                                 $nodes = $torrent['nodes'];
  209.                                                         }
  210.                                                         #*********
  211.                                                         #---------files
  212.                                                         if (is_array($torrent['info']['files'])) {
  213.                                                                 foreach ($torrent['info']['files'] as $key => $value) {
  214.                                                                         if($torrent['info']['files'][$key]['path']) {
  215.                                                                                 $files .= iif(is_array($torrent['info']['files'][$key]['path']), implode('/', $torrent['info']['files'][$key]['path']), $torrent['info']['files'][$key]['path']) . ' (' . vb_number_format($torrent['info']['files'][$key]['length'], 1, true) . ') \n';
  216.                                                                         } else {
  217.                                                                                 $files .= iif(is_array($torrent['info']['files'][$key]['path.utf-8']), implode('/', $torrent['info']['files'][$key]['path.utf-8']), $torrent['info']['files'][$key]['path.utf-8']) . ' (' . vb_number_format($torrent['info']['files'][$key]['length'], 1, true) . ') \n';
  218.                                                                         }
  219.                                                                 }
  220.                                                         }
  221.                                                         #----------
  222.                                                 $info =$bt_head."[b]节点:[/b]\n".$nodes."[b]种子文件:[/b]\n".$files;

  223.                                 }
  224.                         }
  225.                 #}
  226.                 return preg_replace("/\[bt\](.+?)\[\/bt\]/is",$info, $message);
  227.         } else {
  228.                 return $message;  //$infos =info_bt($message);
  229.         }
  230. }
复制代码


在newthread.inc.php搜索

  1. $pinvisible = $modnewthreads ? -2 : 0;
复制代码


在下面添加一句:
  1. $message =info_bt($message);
复制代码
上传文件,覆盖到include目录
宁可枝头抱香死,何曾吹落北风中
头像被屏蔽

0

主题

2414

帖子

2091

积分

落伍者(两全齐美)

独孤太阳

Rank: 2

贡献
0
鲜花
0
注册时间
2007-1-23
发表于 2007-2-3 10:20:39 | 来自 中国浙江杭州
下载了,不鏎
签名被屏蔽

99

主题

1万

帖子

1万

积分

落伍者(四季发财)

phper

Rank: 4

贡献
692
鲜花
29
注册时间
2002-6-19

QQ绑定落伍微信绑定

发表于 2007-2-3 10:22:13 | 来自 中国浙江嘉兴
收藏下

3

主题

1万

帖子

1万

积分

落伍者(四季发财)

无*妻*徒刑

Rank: 4

贡献
0
鲜花
6
注册时间
2004-4-12
 楼主| 发表于 2007-2-3 10:37:00 | 来自 中国广东东莞
如果有朋友的服务器能支持mb_string或iconv的话,不妨发个演示看看,
代码的原理在这里,我兄弟先抛块砖,那位把玉砸过来。

没进行任何美化,就发两截图给大伙看看。
下图应该是[bt] http://127.0.0.1/test.torrent [/bt]
宁可枝头抱香死,何曾吹落北风中

382

主题

31万

帖子

28万

积分

落伍者(八仙过海)

斯大林-enom ETP/新互/新网/22/西数

Rank: 23Rank: 23Rank: 23Rank: 23Rank: 23Rank: 23Rank: 23

贡献
4794
鲜花
794
注册时间
2004-5-18

落伍群众领袖落伍草根英雄QQ绑定落伍手机绑定

发表于 2007-2-3 10:43:47 | 来自 中国江苏连云港
顶啊,喜欢
头像被屏蔽

92

主题

1万

帖子

1万

积分

落伍者(四季发财)

名侦探柯南~~

Rank: 4

贡献
542
鲜花
3
注册时间
2005-7-25
发表于 2007-2-3 10:47:10 | 来自 中国江苏苏州
好东西要收藏
签名被屏蔽
头像被屏蔽

11

主题

1992

帖子

2008

积分

落伍者(两全齐美)

火星主宰者

Rank: 2

贡献
1017
鲜花
2
注册时间
2002-1-23
发表于 2007-2-3 11:00:57 | 来自 中国江苏苏州
好东西要顶
签名被屏蔽

3533

主题

5万

帖子

2万

积分

落伍者(四季发财)

Rank: 4

贡献
3334
鲜花
496
注册时间
2005-9-11

落伍手机绑定

发表于 2007-2-3 11:02:06 | 来自 中国
顶技术帖

58

主题

1万

帖子

1万

积分

落伍者(四季发财)

偶就是流氓

Rank: 4

贡献
77
鲜花
5
注册时间
2003-2-15

QQ绑定落伍者落伍手机绑定

发表于 2007-2-3 11:06:12 | 来自 中国广东东莞
好东东。

3

主题

1万

帖子

1万

积分

落伍者(四季发财)

无*妻*徒刑

Rank: 4

贡献
0
鲜花
6
注册时间
2004-4-12
 楼主| 发表于 2007-2-3 18:29:49 | 来自 中国广东东莞
自己顶一下。。
宁可枝头抱香死,何曾吹落北风中
论坛客服/商务合作/投诉举报:2171544 (QQ)
落伍者创建于2001/03/14,本站内容均为会员发表,并不代表落伍立场!
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!
落伍官方微信:2030286 邮箱:(djfsys@gmail.com|tech@im286.com)
© 2001-2014

浙公网安备 33060302000191号

浙ICP备11034705号 BBS专项电子公告通信管[2010]226号

  落伍法律顾问: ITlaw-庄毅雄

手机版|找回帐号|不能发帖?|Archiver|落伍者

GMT+8, 2024-6-16 07:55 , Processed in 0.128755 second(s), 39 queries , Gzip On.

返回顶部