Discuz教程网

[代码修改] 【Discuz X2视频展厅插件3.1】在不同分类下 调用相应视频的方法

[复制链接]
authicon dly 发表于 2011-11-22 21:10:04 | 显示全部楼层 |阅读模式
首页在vgallery.inc.php 最后加入以下代码
  1. function getFromWhere($where, $num, $is_cache = 0, $cache_name = null) {

  2. $t = time(); // 当前时间戳
  3. $t2 = strtotime("+10 minutes", $t); //更新时间 minutes 分钟 / seconds 秒 / days 天

  4. //是否缓存
  5. if($is_cache == 1){
  6. if(file_exists(DISCUZ_ROOT.'./data/cache/index_new_'.$cache_name.'.hsk')){
  7. @require DISCUZ_ROOT.'./data/cache/index_new_'.$cache_name.'.hsk';
  8. if($t <= $ttime){
  9. return $index_new_array;
  10. }else{
  11. //==============================================10分钟 更新缓存
  12. $query = DB::query("SELECT n.*, t.views as views2, t.replies, p.username FROM pre_vgallerys n
  13. LEFT JOIN ".DB::table('forum_thread')." t ON t.tid=n.tid
  14. LEFT JOIN ".DB::table('common_member')." p ON p.uid=n.uid
  15. where ".$where." and album=0 and audit=1 ORDER BY id desc limit ".$num);
  16. $i = 0;

  17. while($topdata = DB::fetch($query)){
  18. $topdata['vsubjectc'] = cutstr($topdata['vsubject'], 26, '..');
  19. // $topdata['timelong'] = checkthetime($topdata['timelong']);
  20. $topdata['views'] = $topdata['views2'] ? $topdata['views2'] : $topdata['views'];
  21. $topdata['polls'] = $topdata['views2'] ? $topdata['replies'] : $topdata['polls'];
  22. $topdata['valuate'] = sprintf("%01.1f", $topdata['valuate']/100);
  23. $topdata['key'] = $i;
  24. if(substr($topdata['purl'],0,7) != 'http://'){
  25. $thepicurl = DISCUZ_ROOT.$topdata['purl'];
  26. if(!file_exists("$thepicurl") || !$topdata['purl']){
  27. $topdata['purl'] = "./".MDIR."/noimages.gif";
  28. }
  29. }
  30. $cache_str .= "\t".$i."\t=>\t array(\t'vsubject'=>'".$topdata['vsubject']."', \t'vsubjectc'=>'".$topdata['vsubjectc']."', \t'timelong'=>'".$topdata['timelong']."',\t'views'=>'".$topdata['views']."',\t'polls'=>'".$topdata['polls']."',\t'purl'=>'".$topdata['purl']."',\t'id'=>'".$topdata['id']."',\t'username'=>'".$topdata['username']."'),\n";

  31. $i++;
  32. $index_new_array[] = $topdata;

  33. }
  34. $cache_str = "\$ttime = $t2;\n\$index_new_array = array(".$cache_str.");";
  35. frwritecocache('index_new_'.$cache_name, $cache_str);
  36. return $index_new_array;
  37. }
  38. }else{
  39. //==============================================如果没有文件,那么写入
  40. $query = DB::query("SELECT n.*, t.views as views2, t.replies, p.username FROM pre_vgallerys n
  41. LEFT JOIN ".DB::table('forum_thread')." t ON t.tid=n.tid
  42. LEFT JOIN ".DB::table('common_member')." p ON p.uid=n.uid
  43. where ".$where." and album=0 and audit=1 ORDER BY id desc limit ".$num);
  44. $i = 0;

  45. while($topdata = DB::fetch($query)){
  46. $topdata['vsubjectc'] = cutstr($topdata['vsubject'], 26, '..');
  47. $topdata['views'] = $topdata['views2'] ? $topdata['views2'] : $topdata['views'];
  48. $topdata['polls'] = $topdata['views2'] ? $topdata['replies'] : $topdata['polls'];
  49. $topdata['valuate'] = sprintf("%01.1f", $topdata['valuate']/100);
  50. $topdata['key'] = $i;
  51. if(substr($topdata['purl'],0,7) != 'http://'){
  52. $thepicurl = DISCUZ_ROOT.$topdata['purl'];
  53. if(!file_exists("$thepicurl") || !$topdata['purl']){
  54. $topdata['purl'] = "./".MDIR."/noimages.gif";
  55. }
  56. }
  57. $cache_str .= "\t".$i."\t=>\t array(\t'vsubject'=>'".$topdata['vsubject']."', \t'vsubjectc'=>'".$topdata['vsubjectc']."', \t'timelong'=>'".$topdata['timelong']."',\t'views'=>'".$topdata['views']."',\t'polls'=>'".$topdata['polls']."',\t'purl'=>'".$topdata['purl']."',\t'id'=>'".$topdata['id']."',\t'username'=>'".$topdata['username']."'),\n";

  58. $i++;
  59. $index_new_array[] = $topdata;

  60. }
  61. $cache_str = "\$ttime = $t;\n\$index_new_array = array(".$cache_str.");";
  62. frwritecocache('index_new_'.$cache_name, $cache_str);
  63. return $index_new_array;
  64. }
  65. }else{
  66. //==============================================无缓存
  67. $query = DB::query("SELECT n.*, t.views as views2, t.replies, p.username FROM pre_vgallerys n
  68. LEFT JOIN ".DB::table('forum_thread')." t ON t.tid=n.tid
  69. LEFT JOIN ".DB::table('common_member')." p ON p.uid=n.uid
  70. where ".$where." and album=0 and audit=1 ORDER BY id desc limit ".$num);
  71. $i = 0;
  72. while($topdata = DB::fetch($query)){
  73. $topdata['vsubjectc'] = cutstr($topdata['vsubject'], 26, '..');
  74. $topdata['views'] = $topdata['views2'] ? $topdata['views2'] : $topdata['views'];
  75. $topdata['polls'] = $topdata['views2'] ? $topdata['replies'] : $topdata['polls'];
  76. $topdata['valuate'] = sprintf("%01.1f", $topdata['valuate']/100);
  77. $topdata['key'] = $i;
  78. if(substr($topdata['purl'],0,7) != 'http://'){
  79. $thepicurl = DISCUZ_ROOT.$topdata['purl'];
  80. if(!file_exists("$thepicurl") || !$topdata['purl']){
  81. $topdata['purl'] = "./".MDIR."/noimages.gif";
  82. }
  83. }
  84. $i++;
  85. $index_new_array[] = $topdata;

  86. }
  87. return $index_new_array;
  88. }
  89. }
复制代码
函数getFromWhere的参数说明:
$where 为查询的条件  一般为sid = 分类的id号  比如sid=88

$num 调用视频数量
$is_cache 是否调用缓存 值为1时调用缓存
$cache_name 缓存文件名称后辍 以区别不同的缓存文件

函数中
$t2 = strtotime("+10 minutes", $t); //更新时间 minutes 分钟 / seconds 秒 / days 天
默认为10分钟 可根据需要自行修改

如果在视频展厅插件内调用视频 则在模板里
  1. {eval
  2. $index_new_name1 = getFromWhere("sid = 88",22, 1, "name1"); //想要调用的视频
  3. }
  4. <!--{loop $index_new_name1 $i $datarow}-->
  5. $datarow[vsubject] //视频名称
  6. {PDIR}&tion=view&vid=$datarow[id] //视频链接
  7. $datarow[purl] //视频图片地址
  8. $datarow[views] //浏览次数
  9. $datarow[polls] //评论数
  10. <!--{/loop}-->
复制代码


模板可根据自己需要修改 注意所有name1 一定要对应 这个例子调用的视频是 sid为88 调用 22个 1是使用缓存
name1为缓存文件名后辍    name1 则生成的缓存文件名为index_new_name1.hsk

如果在网站其他非视频展厅插件页面调用 稍后更新



上一篇:Discuz X2正式版游客弹窗提醒注册登录插件(可居中,可加广告位,可显示版块简介,最后发
下一篇:Discuz X2 插件开发一些细节记录(作者:nxy105)
authicon 鹤岗 发表于 2011-11-23 22:23:47 | 显示全部楼层
高科技。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 16:16

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表