本帖最后由 与龙共舞 于 2011-12-10 13:18 编辑
视频展厅交流QQ群:13834101
首页在vgallery.inc.php 最后加入以下代码由于一点小疏忽,导致调用的时候有重复数据,请按下面代码72行,对比你原来的文件 把$t改成$t2就行了 2011-12-10 13:14以后用此代码的不用更改
- function getFromWhere($where, $num, $is_cache = 0, $cache_name = null) {
- $t = time(); // 当前时间戳
- $t2 = strtotime("+10 minutes", $t); //更新时间 minutes 分钟 / seconds 秒 / days 天
- //是否缓存
- if($is_cache == 1){
- if(file_exists(DISCUZ_ROOT.'./data/cache/index_new_'.$cache_name.'.hsk')){
- @require DISCUZ_ROOT.'./data/cache/index_new_'.$cache_name.'.hsk';
- if($t <=$ttime ){
- return $index_new_array;
- }else{
- //==============================================10分钟 更新缓存
- $query = DB::query("SELECT n.*, t.views as views2, t.replies, p.username FROM pre_vgallerys n
- LEFT JOIN ".DB::table('forum_thread')." t ON t.tid=n.tid
- LEFT JOIN ".DB::table('common_member')." p ON p.uid=n.uid
- where ".$where." and album=0 and audit=1 ORDER BY id desc limit ".$num);
- $i = 0;
- while($topdata = DB::fetch($query)){
- $topdata['vsubject'] = addslashes($topdata['vsubject']);
- $topdata['vsubjectc'] = cutstr($topdata['vsubject'], 26, '..');
- $topdata['timelong'] = checkthetime($topdata['timelong']);
- $topdata['views'] = $topdata['views2'] ? $topdata['views2'] : $topdata['views'];
- $topdata['polls'] = $topdata['views2'] ? $topdata['replies'] : $topdata['polls'];
- $topdata['valuate'] = sprintf("%01.1f", $topdata['valuate']/100);
- $topdata['key'] = $i;
- if(substr($topdata['purl'],0,7) != 'http://'){
- $thepicurl = DISCUZ_ROOT.$topdata['purl'];
- if(!file_exists("$thepicurl") || !$topdata['purl']){
- $topdata['purl'] = "./".MDIR."/noimages.gif";
- }
- }
- $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";
- $i++;
- $index_new_array[] = $topdata;
- }
- $cache_str = "\$ttime = $t2;\n\$index_new_array = array(".$cache_str.");";
- frwritecocache('index_new_'.$cache_name, $cache_str);
- return $index_new_array;
- }
- }else{
- //==============================================如果没有文件,那么写入
- $query = DB::query("SELECT n.*, t.views as views2, t.replies, p.username FROM pre_vgallerys n
- LEFT JOIN ".DB::table('forum_thread')." t ON t.tid=n.tid
- LEFT JOIN ".DB::table('common_member')." p ON p.uid=n.uid
- where ".$where." and album=0 and audit=1 ORDER BY id desc limit ".$num);
- $i = 0;
- while($topdata = DB::fetch($query)){
- $topdata['vsubject'] = addslashes($topdata['vsubject']);
- $topdata['vsubjectc'] = cutstr($topdata['vsubject'], 26, '..');
- // $topdata['timelong'] = checkthetime($topdata['timelong']);
- $topdata['views'] = $topdata['views2'] ? $topdata['views2'] : $topdata['views'];
- $topdata['polls'] = $topdata['views2'] ? $topdata['replies'] : $topdata['polls'];
- $topdata['valuate'] = sprintf("%01.1f", $topdata['valuate']/100);
- $topdata['key'] = $i;
- if(substr($topdata['purl'],0,7) != 'http://'){
- $thepicurl = DISCUZ_ROOT.$topdata['purl'];
- if(!file_exists("$thepicurl") || !$topdata['purl']){
- $topdata['purl'] = "./".MDIR."/noimages.gif";
- }
- }
- $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";
- $i++;
- $index_new_array[] = $topdata;
- }
- $cache_str = "\$ttime = $t2;\n\$index_new_array = array(".$cache_str.");";
- frwritecocache('index_new_'.$cache_name, $cache_str);
- return $index_new_array;
- }
- }else{
- //==============================================无缓存
- $query = DB::query("SELECT n.*, t.views as views2, t.replies, p.username FROM pre_vgallerys n
- LEFT JOIN ".DB::table('forum_thread')." t ON t.tid=n.tid
- LEFT JOIN ".DB::table('common_member')." p ON p.uid=n.uid
- where ".$where." and album=0 and audit=1 ORDER BY id desc limit ".$num);
- $i = 0;
- while($topdata = DB::fetch($query)){
- $topdata['vsubject'] = addslashes($topdata['vsubject']);
- $topdata['vsubjectc'] = cutstr($topdata['vsubject'], 26, '..');
- // $topdata['timelong'] = checkthetime($topdata['timelong']);
- $topdata['views'] = $topdata['views2'] ? $topdata['views2'] : $topdata['views'];
- $topdata['polls'] = $topdata['views2'] ? $topdata['replies'] : $topdata['polls'];
- $topdata['valuate'] = sprintf("%01.1f", $topdata['valuate']/100);
- $topdata['key'] = $i;
- if(substr($topdata['purl'],0,7) != 'http://'){
- $thepicurl = DISCUZ_ROOT.$topdata['purl'];
- if(!file_exists("$thepicurl") || !$topdata['purl']){
- $topdata['purl'] = "./".MDIR."/noimages.gif";
- }
- }
- $i++;
- $index_new_array[] = $topdata;
- }
- return $index_new_array;
- }
- }
复制代码
函数getFromWhere的参数说明:
$where 为查询的条件 一般为sid = 分类的id号 比如sid=88
$num 调用视频数量
$is_cache 是否调用缓存 值为1时调用缓存
$cache_name 缓存文件名称后辍 以区别不同的缓存文件
函数中
$t2 = strtotime("+10 minutes", $t); //更新时间 minutes 分钟 / seconds 秒 / days 天
默认为10分钟 可根据需要自行修改
如果在视频展厅插件内调用视频 则在模板里
- {eval
- $index_new_name1 = getFromWhere("sid = 88",22, 1, "name1"); //想要调用的视频
- }
- <!--{loop $index_new_name1 $i $datarow}-->
- $datarow[vsubject] //视频名称
- {PDIR}&tion=view&vid=$datarow[id] //视频链接
- $datarow[purl] //视频图片地址
- $datarow[views] //浏览次数
- $datarow[polls] //评论数
- <!--{/loop}-->
复制代码
模板可根据自己需要修改 注意所有name1 一定要对应 这个例子调用的视频是 sid为88 调用 22个 1是使用缓存
name1为缓存文件名后辍 name1 则生成的缓存文件名为index_new_name1.hsk
视频展厅外调用视频 可参考11楼
|