2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Gallery;
|
|
|
|
|
2016-09-03 22:13:05 +01:00
|
|
|
use App\Album;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-07 21:44:28 +01:00
|
|
|
use App\Facade\UserConfig;
|
2016-09-09 16:59:13 +01:00
|
|
|
use App\Helpers\DbHelper;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2017-09-05 22:16:50 +01:00
|
|
|
use App\Photo;
|
2017-04-17 15:45:25 +01:00
|
|
|
use App\VisitorHit;
|
2016-09-06 14:45:51 +01:00
|
|
|
use Illuminate\Http\Request;
|
2016-09-09 16:59:13 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2017-04-17 15:45:25 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2016-09-06 14:45:51 +01:00
|
|
|
public function index(Request $request)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
2017-04-17 21:31:45 +01:00
|
|
|
$albums = DbHelper::getAlbumsForCurrentUser(0);
|
2017-04-10 20:48:47 +01:00
|
|
|
$resetStatus = $request->session()->get('status');
|
2016-09-03 22:13:05 +01:00
|
|
|
|
2017-04-17 15:45:25 +01:00
|
|
|
// Record the visit to the index (no album or photo to record a hit against though)
|
|
|
|
if (UserConfig::get('enable_visitor_hits'))
|
|
|
|
{
|
|
|
|
DB::transaction(function () use ($request)
|
|
|
|
{
|
|
|
|
VisitorHit::fromRequest($request);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-03 22:13:05 +01:00
|
|
|
return Theme::render('gallery.index', [
|
2016-09-06 14:45:51 +01:00
|
|
|
'albums' => $albums,
|
2017-04-10 20:48:47 +01:00
|
|
|
'info' => $request->session()->get('info'),
|
|
|
|
'success' => $resetStatus
|
2016-09-03 22:13:05 +01:00
|
|
|
]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
2017-09-04 22:01:02 +01:00
|
|
|
|
|
|
|
public function sitemapXml()
|
|
|
|
{
|
|
|
|
$xml = new \DOMDocument('1.0', 'UTF-8');
|
|
|
|
$xml->preserveWhiteSpace = true;
|
|
|
|
$xml->formatOutput = true;
|
|
|
|
|
|
|
|
$root = $xml->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
|
2017-09-05 22:16:50 +01:00
|
|
|
$root->appendChild($xml->createAttribute('xmlns:image'))
|
|
|
|
->appendChild($xml->createTextNode('http://www.google.com/schemas/sitemap-image/1.1'));
|
2017-09-04 22:01:02 +01:00
|
|
|
$xml->appendChild($root);
|
|
|
|
|
2017-09-05 22:16:50 +01:00
|
|
|
// Root URL (get last modified photo to create the lastmod date for this URL)
|
|
|
|
$lastModifiedPhoto = Photo::orderBy('updated_at', 'desc')->first();
|
|
|
|
$this->createSitemapNode($xml, $root, route('home'), (is_null($lastModifiedPhoto) ? '' : $lastModifiedPhoto->updated_at), '1.0');
|
|
|
|
|
|
|
|
// Add each album URL
|
|
|
|
$albums = Album::orderBy('name');
|
|
|
|
$albums->chunk(100, function($albumsChunk) use ($xml, $root)
|
|
|
|
{
|
|
|
|
/** @var Album $album */
|
|
|
|
foreach ($albumsChunk as $album)
|
|
|
|
{
|
|
|
|
$lastModifiedPhoto = Photo::where('album_id', $album->id)->orderBy('updated_at', 'desc')->first();
|
|
|
|
$this->createSitemapNode($xml, $root, $album->url(), (is_null($lastModifiedPhoto) ? $album->updated_at : $lastModifiedPhoto->updated_at), '0.9');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add each photo URL
|
|
|
|
$photos = Photo::orderBy('name');
|
|
|
|
$photos->chunk(100, function($tempPhotos) use ($xml, $root)
|
|
|
|
{
|
|
|
|
/** @var Photo $photo */
|
|
|
|
foreach ($tempPhotos as $photo)
|
|
|
|
{
|
|
|
|
$photoMeta = [$photo->name];
|
|
|
|
if (strlen($photo->description) > 0)
|
|
|
|
{
|
|
|
|
$photoMeta[] = $photo->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->createSitemapNode(
|
|
|
|
$xml,
|
|
|
|
$root,
|
|
|
|
$photo->url(),
|
|
|
|
$photo->updated_at,
|
|
|
|
'0.8',
|
|
|
|
$photo->thumbnailUrl('fullsize', false),
|
|
|
|
join(' - ', $photoMeta)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2017-09-04 22:01:02 +01:00
|
|
|
|
|
|
|
return response($xml->saveXML(), 200, ['Content-Type' => 'text/xml']);
|
|
|
|
}
|
|
|
|
|
2017-09-05 22:16:50 +01:00
|
|
|
private function createSitemapNode(
|
|
|
|
\DOMDocument $document,
|
|
|
|
\DOMElement $parentElement,
|
|
|
|
$url,
|
|
|
|
$lastModifiedDate = '',
|
|
|
|
$priority = '',
|
|
|
|
$imageUrl = '',
|
|
|
|
$imageCaption = ''
|
|
|
|
)
|
2017-09-04 22:01:02 +01:00
|
|
|
{
|
|
|
|
$urlElement = $document->createElement('url');
|
2017-09-05 22:16:50 +01:00
|
|
|
|
|
|
|
$urlLocElement = $document->createElement('loc', htmlentities($url));
|
2017-09-04 22:01:02 +01:00
|
|
|
$urlElement->appendChild($urlLocElement);
|
2017-09-05 22:16:50 +01:00
|
|
|
|
|
|
|
$changeFreqElement = $document->createElement('changefreq', 'weekly');
|
|
|
|
$urlElement->appendChild($changeFreqElement);
|
|
|
|
|
|
|
|
if (strlen($lastModifiedDate) > 0)
|
|
|
|
{
|
2017-09-05 22:27:55 +01:00
|
|
|
$lastModElement = $document->createElement('lastmod', date('Y-m-d\TH:i:s+00:00', strtotime($lastModifiedDate)));
|
2017-09-05 22:16:50 +01:00
|
|
|
$urlElement->appendChild($lastModElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($priority) > 0)
|
|
|
|
{
|
|
|
|
$priorityElement = $document->createElement('priority', $priority);
|
|
|
|
$urlElement->appendChild($priorityElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($imageUrl) > 0)
|
|
|
|
{
|
|
|
|
$imageElement = $document->createElement('image:image');
|
|
|
|
|
|
|
|
$imageLocElement = $document->createElement('image:loc', htmlentities($imageUrl));
|
|
|
|
$imageElement->appendChild($imageLocElement);
|
|
|
|
|
|
|
|
$imageCaptionElement = $document->createElement('image:caption', htmlentities($imageCaption));
|
|
|
|
$imageElement->appendChild($imageCaptionElement);
|
|
|
|
|
|
|
|
$urlElement->appendChild($imageElement);
|
|
|
|
}
|
|
|
|
|
2017-09-04 22:01:02 +01:00
|
|
|
$parentElement->appendChild($urlElement);
|
|
|
|
|
|
|
|
return $urlElement;
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|