Repository URL to install this package:
|
Version:
3.2.3 ▾
|
<?php
namespace Evsmash\Articles\Exts;
use Evsmash\Core\Helpers\Str;
use Evsmash\Core\Input\Route;
use Evsmash\Articles\Article;
use Evsmash\Articles\ArticlesCategory;
class Sitemap {
public $output = [];
// generate
public function generate() {
// categories
$this->categories();
// articles
$this->articles();
}
// categories
private function categories() {
// elements
$elements = ArticlesCategory::published()->pluck('name', 'id');
// output
$data = [];
foreach($elements as $id => $name) {
if(isset(cfg('evsmash-articles-slugs')['articles-categories'])) {
$data[] = '/'.Str::slug($name);
} else {
$data[] = Route::map('evsmash/articles/articles/category').'/'.$id.'/'.Str::slug($name);
}
}
// merge
$this->output = array_merge($this->output, $data);
}
// articles
private function articles() {
// elements
$elements = Article::published()->pluck('slug', 'id');
// output
$data = [];
foreach($elements as $id => $slug) {
if(isset(cfg('evsmash-articles-slugs')['articles'])) {
$data[] = '/'.Str::slug($slug);
} else {
$data[] = Route::map('evsmash/articles/articles/show').'/'.$id.'/'.Str::slug($slug);
}
}
// merge
$this->output = array_merge($this->output, $data);
}
}