Пример #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->is("sitemap") && $request->fullUrl() != '' && $this->auth->guest()) {
         $aSiteMap = \Cache::get('sitemap', []);
         $changefreq = 'always';
         if (!empty($aSiteMap[$request->fullUrl()]['added'])) {
             $aDateDiff = Carbon::createFromTimestamp($aSiteMap[$request->fullUrl()]['added'])->diff(Carbon::now());
             if ($aDateDiff->y > 0) {
                 $changefreq = 'yearly';
             } else {
                 if ($aDateDiff->m > 0) {
                     $changefreq = 'monthly';
                 } else {
                     if ($aDateDiff->d > 6) {
                         $changefreq = 'weekly';
                     } else {
                         if ($aDateDiff->d > 0 && $aDateDiff->d < 7) {
                             $changefreq = 'daily';
                         } else {
                             if ($aDateDiff->h > 0) {
                                 $changefreq = 'hourly';
                             } else {
                                 $changefreq = 'always';
                             }
                         }
                     }
                 }
             }
         }
         $aSiteMap[$request->fullUrl()] = ['added' => time(), 'lastmod' => Carbon::now()->toIso8601String(), 'priority' => 1 - substr_count($request->getPathInfo(), '/') / 10, 'changefreq' => $changefreq];
         \Cache::put('sitemap', $aSiteMap, 2880);
     }
     return $next($request);
 }
Пример #2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $array = [];
     /*
           $t = microtime(true);
             $micro = sprintf("%06d",($t - floor($t)) * 1000000);
             $d = new \DateTime( date('Y-m-d H:i:s.'.$micro, $t) );
     */
     $time_now = Carbon::now();
     //$dd = "2016-03-20T18:00:30+0000" ;
     $dd = $time_now->toIso8601String();
     //  $microSeconds = str_replace("+0000","+02:00", $dd);
     if (!$request->is("sitemap") && $request->fullUrl() != '' && $this->auth->guest()) {
         $aSiteMap = \Cache::get('sitemap', []);
         $changefreq = 'always';
         if (!empty($aSiteMap[$request->fullUrl()]['added'])) {
             $aDateDiff = Carbon::createFromTimestamp($aSiteMap[$request->fullUrl()]['added'])->diff($time_now);
             if ($aDateDiff->y > 0) {
                 $changefreq = 'yearly';
             } else {
                 if ($aDateDiff->m > 0) {
                     $changefreq = 'monthly';
                 } else {
                     if ($aDateDiff->d > 6) {
                         $changefreq = 'weekly';
                     } else {
                         if ($aDateDiff->d > 0 && $aDateDiff->d < 7) {
                             $changefreq = 'daily';
                         } else {
                             if ($aDateDiff->h > 0) {
                                 $changefreq = 'hourly';
                             } else {
                                 $changefreq = 'always';
                             }
                         }
                     }
                 }
             }
         }
         $aSiteMap[$request->fullUrl()] = ['added' => time(), 'lastmod' => $dd, 'priority' => 1 - substr_count($request->getPathInfo(), '/') / 10, 'changefreq' => 'always'];
         \Cache::put('sitemap', $aSiteMap, 2880);
     }
     return $next($request);
 }