<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\News\Util; use Illuminate\Support\Facades\Cache; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Util\ArrayUtil; use ModStart\Core\Util\HtmlUtil; use ModStart\Core\Util\TimeUtil; class NewsUtil { public static function clearCache() { for ($Gm19h = 0; $Gm19h < 20; $Gm19h++) { Cache::forget('NewsLatest:' . $Gm19h); } } public static function buildRecord($Lu5WV) { goto hnR9k; hnR9k: $qgfZ7 = ArrayUtil::keepKeys($Lu5WV, array('id', 'cover', 'title', 'updated_at', 'summary')); goto FY6le; gdEC1: return $qgfZ7; goto OHhVO; NMvmS: if (empty($Lu5WV['cover'])) { $k1_u1 = HtmlUtil::extractTextAndImages($Lu5WV['content']); if (!empty($k1_u1['images'])) { $qgfZ7['cover'] = $k1_u1['images'][0]; } } goto gdEC1; FY6le: $qgfZ7['day'] = date('Y-m-d', strtotime($Lu5WV['created_at'])); goto NMvmS; OHhVO: } public static function buildRecords($vKRZ2) { foreach ($vKRZ2 as $l0ek5 => $Lu5WV) { $vKRZ2[$l0ek5] = self::buildRecord($Lu5WV); } return $vKRZ2; } public static function listLatest($BMu21 = 5) { return Cache::remember('NewsLatest:' . $BMu21, TimeUtil::MINUTE_PERIOD_DAY, function () use($BMu21) { $vKRZ2 = ModelUtil::model('news')->orderBy('id', 'desc')->limit($BMu21)->get()->toArray(); return self::buildRecords($vKRZ2); }); } public static function get($WXJys) { return ModelUtil::get('news', array('id' => $WXJys)); } public static function listCategories() { return ModelUtil::model('news_category')->orderBy('sort', 'asc')->get()->toArray(); } }