Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Classes/Repositories/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ArticleRepository extends BaseRepository
*/
public function __construct(Article $model)
{
$this->model = $model;
$this->model = $model->withoutGlobalScopes();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Classes/Repositories/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function all()
*/
public function allDescendingOrder()
{
return $this->model->orderBy('created_at', 'desc')->get();
return $this->model->withoutGlobalScopes()->orderBy('created_at', 'desc')->get();
}

/**
Expand Down
35 changes: 23 additions & 12 deletions app/Model/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,32 @@ class Article extends Model implements Linkable
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'publish_date', 'unpublish_date'];

/**
* Undocumented function.
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
parent::boot();

static::addGlobalScope('published', function (Builder $builder) {
return $builder->where([
['publish_date', '<=', Carbon::now()],
['unpublish_date', '>', Carbon::now()],
['status', '=', true],
])->orWhere([
['publish_date', '<=', Carbon::now()],
['unpublish_date', '=', null],
['status', '=', true],
]);
});
}

/**
* Undocumented function.
*
* @return string
*/
public function getRouteKeyName()
{
return 'slug';
Expand Down Expand Up @@ -160,17 +182,6 @@ public function setTitleAttribute($value)
$this->attributes['slug'] = str_slug($value);
}

/**
* Scope the collection to only published.
*
* @param Builder $query
* @return Builder
*/
public function scopePublished(Builder $query)
{
return $query->where('status', true);
}

/**
* The url that is used to view this model.
* The category will be prefixed if one exists.
Expand Down
23 changes: 18 additions & 5 deletions app/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @method static Builder sitemap() Query only pages that are for sitemap.
*
* @return Page|Collection|Builder
*/
class Page extends Model implements Linkable
Expand Down Expand Up @@ -106,7 +108,7 @@ public function getDescriptionForEvent(string $eventName): string
/**
* Undocumented function.
*
* @return void
* @return string
*/
public function getRouteKeyName()
{
Expand All @@ -117,22 +119,22 @@ public function getRouteKeyName()
* Return the path to the page, these can sometimes have a prefix
* attached.
*
* @return void
* @return string
*/
public function path()
{
if ($this->prefix) {
return "{$this->prefix}/{$this->slug}";
return url("{$this->prefix}/{$this->slug}");
}

return "{$this->slug}";
return url("{$this->slug}");
}

/**
* Undocumented function.
*
* @param string $string
* @return void
* @return Page
*/
public static function whereIdentifier(string $string)
{
Expand Down Expand Up @@ -199,6 +201,17 @@ public function linked()
return $this->morphMany(Link::class, 'to');
}

/**
* Scope a query to only include sitemap pages.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSitemap($query)
{
return $query->where('option', '&', PageOptions::OPTION_SITEMAP);
}

/**
* The url that is used to view this model.
*
Expand Down
2 changes: 2 additions & 0 deletions app/Modules/Articles/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public function categories_store(Request $request)
* @param int $id
* @param ArticleCategoryRepository $categoryRepository
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Exception
*/
public function categories_destroy(int $id, ArticleCategoryRepository $categoryRepository)
{
Expand Down
42 changes: 8 additions & 34 deletions app/Modules/Articles/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
use App\Model\Categories;
use App\Jobs\IncrementViews;
use Illuminate\Http\Request;
use App\Classes\SitemapGenerator;
use App\Classes\Interfaces\Sitemap;
use Illuminate\Support\Facades\View;
use App\Classes\Repositories\PageRepository;
use App\Classes\Library\PageLoader\Frontpage;
use App\Classes\Repositories\ArticleRepository;

/**
* Class UserController.
*/
class FrontendController implements Sitemap
class FrontendController
{
/**
* @var Page
Expand All @@ -43,7 +40,7 @@ public function __construct()
*/
public function allArticles(Article $article)
{
View::share('articles', $article->published()->latest('created_at')->paginate(7));
View::share('articles', $article->latest('created_at')->paginate(7));

return Frontpage::build($this->currentPage, 200, 'articles');
}
Expand All @@ -54,7 +51,7 @@ public function allArticles(Article $article)
* @param Categories $category The articles category.
* @param Article $article The article model to interact with.
*
* @return void
* @return Frontpage
*/
public function viewArticle($category, Article $article)
{
Expand All @@ -70,26 +67,24 @@ public function viewArticle($category, Article $article)
/**
* View all articles in the category.
*
* @param ArticleRepository $repository
* @param string $string
* @return void
* @return Frontpage
*/
public function categoryArticles(Categories $category)
{
View::share('articles', $category->articles()->where('status', true)->paginate(7));
View::share('articles', $category->articles()->paginate(7));

$this->currentPage->heading = 'Browse Categories';

return Frontpage::build($this->currentPage, 200, 'articles');
}

/**
* Search all articles and return results.
* Search Articles.
*
* @param ArticleRepository $repository
* @param Request $request
*
* @return void
* @return Frontpage
*/
public function searchArticles(Request $request)
{
Expand All @@ -103,36 +98,15 @@ public function searchArticles(Request $request)
/**
* Get all the articles created by an account.
*
* @param ArticleRepository $repository
* @param int $id
* @return Frontpage
*/
public function allCreatorsArticles(ArticleRepository $repository, Account $account)
public function allCreatorsArticles(Account $account)
{
$this->currentPage->heading = 'Browse Creators';

View::share('articles', $account->articles()->paginate(7));

return Frontpage::build($this->currentPage, 200, 'articles');
}

/**
* The sitemap function allows plugins to quickly and effectively
* show their content for search engines in a modular way.
*
* @param SitemapGenerator $sitemap
* @return SitemapGenerator
*/
public function sitemap(SitemapGenerator $sitemap)
{
/** @var ArticleRepository $repository */
$repository = app(ArticleRepository::class);

/** @var Article $article */
foreach ($repository->whereSitemappable() as $article) {
$sitemap->store(url($article->route()), $article->updated_at, 'weekly', '1.0');
}

return $sitemap;
}
}
10 changes: 2 additions & 8 deletions app/Modules/Configs/Controller.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<?php
/**
* Created by PhpStorm.
* User: Mark
* Date: 11/03/2016
* Time: 17:32.
*/

namespace App\Modules\Settings;
namespace App\Modules\Configs;

use App\Model\Configuration;
use App\Modules\ModuleEngine;
Expand Down Expand Up @@ -39,7 +33,7 @@ public function index()
}

/**
* Save the changes for settings.
* Save the changes for system_config.
*
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
Expand Down
24 changes: 24 additions & 0 deletions app/Modules/Sitemap/Blade/sitemap.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?= '<'.'?'.'xml version="1.0" encoding="UTF-8"?>'."\n" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">

@foreach ($urlset as $set)
<url>
@if (! empty($set['loc']))
<loc>{{ $set['loc'] }}</loc>
@endif

@if (! empty($set['lastmod']))
<lastmod>{{ $set['lastmod'] }}</lastmod>
@endif

@if (! empty($set['changefreq']))
<changefreq>{{ $set['changefreq'] }}</changefreq>
@endif

@if (! empty($set['priority']))
<priority>{{ $set['priority'] }}</priority>
@endif
</url>
@endforeach

</urlset>
2 changes: 1 addition & 1 deletion app/Modules/Sitemap/Routes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Get Requests.
// ==================================================================================
//Route::get('/sitemap.xml')->uses('Controller@all')->name('sitemap');
Route::get('/sitemap.xml')->uses('SitemapController@index')->name('sitemap');

// Post Requests.
// ==================================================================================
37 changes: 37 additions & 0 deletions app/Modules/Sitemap/SitemapConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Modules\Sitemap;

/**
* Class SitemapConstants.
*/
class SitemapConstants
{
/**
* How frequently the page is likely to change.
* This value provides general information to search engines
* and may not correlate exactly to how often they crawl the
* page.
*/
const FREQUENCY_ALWAYS = 'always';
const FREQUENCY_HOURLY = 'hourly';
const FREQUENCY_DAILY = 'daily';
const FREQUENCY_WEEKLY = 'weekly';
const FREQUENCY_MONTHLY = 'monthly';
const FREQUENCY_YEARLY = 'yearly';
const FREQUENCY_NEVER = 'never';

/**
* The priority of this URL relative to other URLs on your site.
* Valid values range from 0.0 to 1.0. This value does not affect
* how your pages are compared to pages on other sites—it only
* lets the search engines know which pages you deem most
* important for the crawlers.
*/
const PRIORITY_HIGHEST = 1.0;
const PRIORITY_HIGH = 0.8;
const PRIORITY_NORMAL = 0.5;
const PRIORITY_LOW = 0.3;
const PRIORITY_LOWEST = 0.1;
const PRIORITY_NONE = 0.0;
}
52 changes: 52 additions & 0 deletions app/Modules/Sitemap/SitemapController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Modules\Sitemap;

use App\Model\Page;
use App\Model\Article;
use App\Modules\ModuleEngine;
use Illuminate\Http\Response;
use App\Modules\Sitemap\SitemapConstants as Sitemap;

/**
* Class Controller.
*
* Generate the site content sitemap.xml for SEO.
*/
class SitemapController extends ModuleEngine
{
/**
* @var SitemapGenerator
*/
private $sitemap;

/**
* Controller constructor.
*
* @param SitemapGenerator $sitemap
*/
public function __construct(SitemapGenerator $sitemap)
{
$this->sitemap = $sitemap;
}

/**
* Return a response encoded with xml for sitemap.xml viewing.
*
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
public function index()
{
/** @var Page $page */
foreach (Page::sitemap()->get() as $page) {
$this->sitemap->add($page->path())->modified($page->updated_at)->withFrequency(Sitemap::FREQUENCY_WEEKLY)->andPriority(Sitemap::PRIORITY_NORMAL);
}

/** @var Article $article */
foreach (Article::all() as $article) {
$this->sitemap->add($article->path())->modified($article->updated_at)->withFrequency(Sitemap::FREQUENCY_WEEKLY)->andPriority(Sitemap::PRIORITY_NORMAL);
}

return response($this->make('sitemap')->with('urlset', $this->sitemap->collection()), 200, ['Content-type' => 'text/xml']);
}
}
Loading