📄 function.php
字号:
$i=0; foreach($rows as $row) { $i++; $urls=getDownloadUrl($row); extract($urls); $start = ($i%$cols==1)||($cols==1); $end = ($i%$cols==0)||($cols==1)||($nums==$i); # mixed in ads! if($row[is_ads]==1) $template->assign_block_vars('row',array( 'is_end' => $end, 'is_start' => $start, 'is_ads' => 1 )); else $template->assign_block_vars('row', array( 'downloadurl' => $downloadurl, 'thumburl' => $thumburl, 'size' => convertsize($row[size]), 'descr' => $row[descr], 'name' => $row[name], 'add_date' => date('M d,Y H:i',$row['time']), 'add_days' => intval((time()-$row['time'])/(24*3600)), 'is_end' => $end, 'is_start' => $start, 'is_ads' => 0, )); ($hook = YABPlugin::fetch_hook('topfiles_row',__FILE__,__LINE__)) ? eval($hook) : ''; } ($hook = YABPlugin::fetch_hook('topfiles_end',__FILE__,__LINE__)) ? eval($hook) : '';}/*** get total files to be listed*/function GetFileNums(){global $db,$user; ($hook = YABPlugin::fetch_hook('getfiles_total',__FILE__,__LINE__)) ? eval($hook) : ''; $condiftion = ($user->setting[featured_type]?"f.validate=1 AND" : "") . " f.thumb=1"; $nowtime=time(); $db->setQuery("SELECT count(f.id) as num FROM files as f WHERE $condiftion AND f.deleted=0"); $db->query(); $row=$db->loadRow(); return $row[num];}/***Build url for download files,short, seo url* @info =array('id'=>,'file'=>,'upload_id'=>,'delete_id'=>,'thumb'=>,'http'=>,'domain'=>,)*/function getDownloadUrl($info, $urltype=''){global $langWeb,$baseWeb,$user; ($hook = YABPlugin::fetch_hook('getdllinks_prepare',__FILE__,__LINE__)) ? eval($hook) : ''; # get thumbnail url $ImageFile= array('jpg','jpeg','gif','png'); $filetype = getExt($info[file],'_')?getExt($info[file],'_'):getExt($info[file]); $thumbfilename = !in_array($filetype,$ImageFile) ? substr($info[file],0,-(strlen($filetype)+1)).'.jpg':str_replace('_','.',$info[file]); # get thumbnail url if($info[thumb]==1) { $return[thumburl] = $info[http].$info[domain].'/thumb/thumb_'.$thumbfilename; } elseif($info[thumb]==0) { $return[thumburl] = $baseWeb.'/skin/'.$user->setting[skin_dir].'/thumb/soon.jpg'; } else { $return[thumburl] = $baseWeb.'/skin/'.$user->setting[skin_dir].'/thumb/thumb_'.$filetype.'.jpg'; } $urltype = $urltype ? $urltype : $user->setting[static_url]; # get download url for different modes if($urltype=='short') { $return[downloadurl]=$baseWeb.'/?d='.$info[upload_id]; $return[deleteurl]=$baseWeb.'/?d='.$info[upload_id].$info[delete_id]; } elseif($urltype=='seo') { $return[downloadurl]=$langWeb.'/file/'.$info[id].'/'.makeurls($info[name]).'.html'; $return[deleteurl]=$langWeb.'/delete.php?id='.$info[upload_id].$info[delete_id]; } else { $return[downloadurl]=$langWeb.'/download.php?id='.$info[upload_id]; $return[deleteurl]=$langWeb.'/delete.php?id='.$info[upload_id].$info[delete_id]; } ($hook = YABPlugin::fetch_hook('getdllinks_return',__FILE__,__LINE__)) ? eval($hook) : ''; return $return;}/***Build url for download files,short, seo url*/function validateDownloadUrl($urls){global $baseWeb,$db; ($hook = YABPlugin::fetch_hook('checkdllinks_begin',__FILE__,__LINE__)) ? eval($hook) : ''; # extract nice info $parts = parse_url($baseWeb); $domain = strtolower(substr($parts[host],0,4))=='www.' ? substr($parts[host],4):$parts[host]; $path = str_replace('/','([/]?)',$parts[path]); # build reg patern $match=array(); $match[dyn] = "'$parts[scheme]://([www\.]{0,4})$domain$path([/]?)([a-z]{0,2})([/]?)download.php\?id=([A-Z0-9]+)'"; $match[short] = "'$parts[scheme]://([www\.]{0,4})$domain$path([/]+)\?d=([A-Z0-9]+)'"; $match[seo] = "'$parts[scheme]://([www\.]{0,4})$domain$path([/]?)([a-z]{0,2})([/]?)file([/]+)([0-9]+)/(.*)'"; # process the $upload_id=$file_id=array(); if($urls) foreach($urls as $url) { if(preg_match($match[dyn], $url, $matchesL)) { $upload_id[] = "'".$matchesL[count($matchesL)-1]."'"; } elseif(preg_match($match[seo], $url, $matchesL)) { $file_id[] = $matchesL[count($matchesL)-2]; } elseif(preg_match($match[short], $url, $matchesL)) { $upload_id[] = "'".$matchesL[count($matchesL)-1]."'"; } } else { return 0; } # build query $upload_ids=implode(',',$upload_id); $file_ids=implode(',',$file_id); $upload_ids = $upload_ids ? "upload_id in ($upload_ids) or " : ''; $file_ids = $file_ids ? "id in ($file_ids)" : '0'; if(!$upload_ids&&!$file_ids) return 0; # check against db $db->setQuery("select id from files where ($upload_ids $file_ids) and deleted=0"); $db->query(); $rows = $db->loadRowList('id'); if(!count($rows)) return 0; return array_keys($rows);}/*** get the urls for admin panel!*/function getUrls($filename,$sourceWeb,$exists=0){global $baseWeb,$SET; $filetype = getExt($filename,'_')?getExt($filename,'_'):getExt($filename); $SET[skin_dir]='default'; $ImageFile= array('jpg','jpeg','gif','png'); if(!in_array($filetype,$ImageFile)) { $thumbfilename = basename(substr($filename,0,-(strlen($filetype)+1)).'.jpg'); } else { $thumbfilename = basename(str_replace('_','.',$filename)); } $fileurl=$sourceWeb.'/admin/download.php?f='.$filename; if($exists==1) { $thumburl=$sourceWeb.'/thumb/thumb_'.($thumbfilename); } elseif($exists==0) { $thumburl=$baseWeb.'/skin/'.$SET[skin_dir].'/thumb/cominigsoon.gif'; } else { $thumburl=$baseWeb.'/skin/'.$SET[skin_dir].'/thumb/thumb_'.$filetype.'.jpg'; } return array('thumburl'=>$thumburl,'fileurl'=>$fileurl);}/*** get the urls for fodlers!*/function getFolderUrl($info,$isadmin=0){global $baseWeb,$SET,$langWeb; $folderurl = $langWeb.'/folders/'.$info[fid].'/'.makeurls($info[name]).'.html'; return $folderurl;}/*** auth the remote access to upload thumb!*/function verify_admin_access(){global $db,$input; $timeout = time() - 3600; $db->setQuery("select * from setting where admin_lastclick > $timeout and admin_ip= '$input[IP_CLIENT]'"); $db->query(); return $db->getNumRows();}/*** build lang list!*/function build_lang_list($mylang='',$type='url'){global $LANG_TO_MATCH, $CODE_TO_LANG; $lang_list = ''; foreach($LANG_TO_MATCH as $lang=>$matchcode) { $lang_code = array_search($lang,$CODE_TO_LANG); $lang_list .= '<option value="'.$lang_code.'" '.((is_array($mylang)?in_array($lang_code,$mylang):$lang_code==$mylang)?' selected':'').'>'.$lang.($type=='url'?'[?setlang='.$lang_code.'])':'').'</option>'; } return $lang_list;}/*** build lang list!*/function build_country_list($mycountry=''){global $GEOIP_COUNTRY_NAMES, $GEOIP_COUNTRY_CODES; $country_list = ''; foreach($GEOIP_COUNTRY_NAMES as $id=>$country) { if($country) $country_list .= '<option value="'.$GEOIP_COUNTRY_CODES[$id].'" '.((is_array($mycountry)?in_array($GEOIP_COUNTRY_CODES[$id],$mycountry):$GEOIP_COUNTRY_CODES[$id]==$mycountry)?' selected':'').'>'.$country.'</option>'; } return $country_list;}/*** site stats:today/yesterday uploads*/function siteStats(){global $db,$user,$template; # check sitestats is enabled if($user->setting[sitestats]!=1) return 0; # build date filter $today=date('d'); $month=date('m'); $year=date('y'); $today_time=mktime(0,0,0,$month,$today,$year); $yestoday_time=mktime(0,0,0,$month,$today-1,$year); $thisweek_time=mktime(0,0,0,$month,$today-6,$year); # get stats from db $db->setQuery("select count(*) as nums,count(if(time>$today_time,1,NULL)) as todays,count(if($today_time>time and time>$yestoday_time,1,NULL)) as yesterdays from files where deleted=0"); $db->query(); $stats=$db->loadRow(); $totalfiles=$stats[nums]; $todayfiles=$stats[todays]; $yesterdayfiles=$stats[yesterdays]; $db->setQuery("select count(*) as num from users"); $db->query(); $stats=$db->loadRow(); $totalusers=$stats[num]; # template assigning $template->assign_var('show_site_stats',$user->setting[sitestats]); $template->assign_vars(array( 'todayfiles'=>$todayfiles, 'yesterdayfiles'=>$yesterdayfiles, 'totalfiles'=>$totalfiles, 'totalusers'=>$totalusers, )); ($hook = YABPlugin::fetch_hook('sitestats_display',__FILE__,__LINE__)) ? eval($hook) : '';}/*** show news*/function showNews($clientarea=0,$titleonly=1){global $input,$db,$user,$template; $nowtime=time(); if($user->uid==0) $wherex=' AND public=1'; if($clientarea==1) $wherex=' AND public=0'; $limit=$clientarea?'limit 5':''; $db->setQuery("select * from news where ((start_date<=$nowtime AND end_date>=$nowtime) OR (start_date=0 AND end_date=0) OR (start_date is null AND end_date is null) ) and lang in('na','$user->langcode') $wherex order by date desc $limit"); $db->query(); $rows=$db->loadRowList(); if(!$rows) return ''; foreach($rows as $row) { ($hook = YABPlugin::fetch_hook('news_row',__FILE__,__LINE__)) ? eval($hook) : ''; $template->assign_block_vars('news', array( 'id' =>$row[news_id], 'title' =>$row[title], 'publish_date' =>date(DateFormat,$row[date]), 'body' =>$row[body], ) ); }}/** build nav pages links*/function buildPageLinks($info,$static=0){global $input,$baseUrl,$LANG; if(!is_array($LANG)) { $LANG[Pages]='Pages'; $LANG[LastPage]='Last page'; $LANG[NextPage]='Next page'; } $pages= @ceil($info[total]/$info[page]); if($pages==1 || $pages== 0) return; $span=10; $s=intval(($info[cur_page]/$span))*$span; for($i=$s;$i<$s+$span; $i++) { if($i>=$pages) break; $start=$i*$info[page]; $tag=$i+1; if($tag==$info[cur_page]+1) { $html.=" <b>$tag</b>"; } else { if($static) $html.=" <a href='$info[baseUrl]/{$tag}.html' class=pagenav>$tag</a>"; else $html.=" <a href='$info[baseUrl]&s=$start' class=pagenav>$tag</a>"; } } $start+=$info[page]; if($start>$info[total]) $start-=$info[page]; $start2=$s*($info[page]-1); $endpage=($pages-1)*$info[page]; if($static) return "<a href='$info[baseUrl]/".($start2/$info[page]?$start2/$info[page]:'index.html')."' class=pagenav>$LANG[FirstPage]</a> <a href='$info[baseUrl]/".($start2/$info[page]+1).".html'><<</a>".$html." <a href='$info[baseUrl]/".($start/$info[page]+1).".html'>>></a> <a href='$info[baseUrl]/".($endpage/$info[page]+1).".html'>$LANG[LastPage]</a>($pages $LANG[Pages])"; else return "<a href='$info[baseUrl]&s=$start2' class=pagenav>$LANG[FirstPage]</a> <a href='$info[baseUrl]&s=$start2'><<</a>".$html." <a href='$info[baseUrl]&s=$start'>>></a> <a href='$info[baseUrl]&s=$endpage'>$LANG[LastPage]</a> ($pages $LANG[Pages])";}/*** get extention by the specified separater*/function getExt($name,$sep='.'){ $ext = substr(strtolower(strrchr($name,$sep)),1); #if($ext==''&&strpos($name,$sep)!==false) return ' '; return $ext;}/*** keep extention or not by the specified separater*/function keepExt($name,$sep='.'){ $ext = substr(strtolower(strrchr($name,$sep)),1); if($ext==''&&strpos($name,$sep)!==false) return ' '; return $ext;}/*** calculate the progress bar info*/function showStatus($iTotal,$iRead,$dtstart){global $dtRemainingf,$dtelapsedf,$bSpeedf,$percent; ## # Elapsed time # Calculate elapsed time and format for display ## $dtnow=time(); $dtelapsed = $dtnow - $dtstart;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -