$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}"; } //参数:page、limit public static function getPaginationLink($url, $page, $pageSize = 24) { $arr = explode('?', $url); if (count($arr) == 1) { //不含问号 return "{$url}?page={$page}&limit={$pageSize}"; } $paginationParams = array('page', 'limit'); $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 (!in_array($name, $paginationParams)) { array_push($newParms, $item); } } } return $baseUrl . "?page={$page}&limit={$pageSize}" . (!empty($newParms) ? '&'.implode('&', $newParms) : ''); } //输出翻页组件,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 = $page > 5 ? $page - 5 : 1; $endPage = $startPage + 10 < $maxPage ? $startPage + 10 : $maxPage; for ($i = $startPage; $i <= $endPage; $i ++) { $url = self::getPaginationLink($currentUrl, $i, $limit); if ($i != $page) { $otherLinks .= <<{$i} eof; }else { $otherLinks .= << {$i} eof; } } $html = <<
    {$previousLink} {$otherLinks} {$nextLink}
  • 总数 {$total}
eof; return $html; } }