$item) {
$ctimes[$id] = $item['fstat']['ctime'];
}
if ($way == 'desc') {
arsort($ctimes, SORT_NUMERIC);
}else {
asort($ctimes, SORT_NUMERIC);
}
$sorted = array();
foreach($ctimes as $id => $ctime) {
array_push($sorted, $files[$id]);
}
return $sorted;
}
//生成GA统计代码
public static function getGACode() {
if (!empty(FSC::$app['config']['debug'])) {return '';}
$msid = !empty(FSC::$app['config']['GA_MEASUREMENT_ID']) ? FSC::$app['config']['GA_MEASUREMENT_ID'] : '';
if (empty($msid)) {return '';}
$adwords_id = !empty(FSC::$app['config']['GAD_MEASUREMENT_ID']) ? FSC::$app['config']['GAD_MEASUREMENT_ID'] : '';
$gacode = <<
eof;
return $gacode;
}
//根据收藏和分类,获取单个收藏视频的所在分类
public static function getFavsTags($filename, $tags) {
$fileTags = array();
foreach($tags as $tag_id => $item) {
if (in_array($filename, $item['files'])) {
array_push($fileTags, $item['name']);
}
}
return $fileTags;
}
//获取只包含分类名的数组
public static function getTagNames($tags) {
$tmp_arr = array();
foreach ($tags as $id => $tag) {
array_push($tmp_arr, $tag['name']);
}
return $tmp_arr;
}
//获取用户图片的cdn地址
public static function getCDNImageUrl($localImgUrl) {
if (!empty(FSC::$app['config']['debug'])) {return $localImgUrl;}
$cdn = FSC::$app['config']['img_cdn_budget_url'];
if (empty($cdn)) {return $localImgUrl;}
return "{$cdn}{$localImgUrl}";
}
//根据文件类型,获取数组中符合条件文件总数
public static function getDataTotal($files, $fileTypes) {
$total = 0;
foreach ($files as $file) {
if (empty($file['extension']) || !in_array($file['extension'], $fileTypes)) {
continue;
}
$total ++;
}
return $total;
}
//根据指定参数,以及当前网址,生成新的网址
public static function getLinkByParams($url, $getParams = array()) {
$arr = explode('?', $url);
if (count($arr) == 1) { //不含问号
return "{$url}?" . http_build_query($getParams);
}
$newParms = array();
$baseUrl = $arr[0];
$queryString = $arr[1];
$params = explode('&', $queryString);
if (count($params) > 0) {
foreach ($params as $item) {
list($name, $val) = explode('=', $item);
if (!isset($getParams[$name])) {
array_push($newParms, $item);
}
}
}
return "{$baseUrl}?" . http_build_query($getParams) . (!empty($newParms) ? '&'.implode('&', $newParms) : '');
}
//参数:page、limit
public static function getPaginationLink($url, $page, $limit = 24) {
$paginationParams = compact('page', 'limit');
return self::getLinkByParams($url, $paginationParams);
}
//输出翻页组件,page从1开始
public static function getPaginationHtmlCode($page, $limit, $total) {
$currentUrl = FSC::$app['requestUrl'];
$maxPage = ceil($total / $limit);
//上一页
$previousLink = <<
上一页
eof;
if ($page > 1) {
$url = self::getPaginationLink($currentUrl, $page-1, $limit);
$previousLink = <<
上一页
eof;
}
//下一页
$nextLink = <<
下一页
eof;
if ($page < $maxPage) {
$url = self::getPaginationLink($currentUrl, $page+1, $limit);
$nextLink = <<
下一页
eof;
}
//包括当前页一共显示 10 页
$otherLinks = '';
$startPage = floor(($page-1) / 10)*10 + 1;
$endPage = $startPage + 9 < $maxPage ? $startPage + 9 : $maxPage;
for ($i = $startPage; $i <= $endPage; $i ++) {
$url = self::getPaginationLink($currentUrl, $i, $limit);
if ($i != $page) {
$otherLinks .= <<{$i}
eof;
}else {
$otherLinks .= <<
{$i}
eof;
}
}
$html = <<
eof;
return $html;
}
public static function getMediaSourceType($fileExtension) {
$sourceType = 'video/mp4';
if ($fileExtension == 'mov') {
$sourceType = 'video/mp4';
}else if ($fileExtension == 'm3u8') {
$sourceType = 'application/x-mpegURL';
}else if ($fileExtension == 'mp3') {
$sourceType = 'audio/mp3';
}
return $sourceType;
}
//根据文件名,找出同名的图片文件
public static function searchImageByFilename($filename, $files, $imgExts = array('jpg', 'jpeg', 'png', 'webp', 'gif', 'svg')) {
$matchedImage = null;
if (!empty($files)) {
foreach($files as $item) {
if (!empty($item['filename']) && $item['filename'] == $filename && in_array($item['extension'], $imgExts)) {
$matchedImage = $item;
break;
}
}
}
return $matchedImage;
}
}