-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from tbreuss/feat-dynamic-pages
Feat dynamic pages
- Loading branch information
Showing
12 changed files
with
148 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace app\components; | ||
|
||
use yii\base\BaseObject; | ||
use yii\web\Request; | ||
use yii\web\UrlManager; | ||
use yii\web\UrlRuleInterface; | ||
|
||
final class PageUrlRule extends BaseObject implements UrlRuleInterface | ||
{ | ||
/** | ||
* @param UrlManager $manager | ||
* @param Request $request | ||
* @return array|bool | ||
* @phpstan-return array<int, array<string, string>|string>|bool | ||
* @throws \yii\base\InvalidConfigException | ||
*/ | ||
public function parseRequest($manager, $request) | ||
{ | ||
$pathInfo = $request->getPathInfo(); | ||
if ($pathInfo !== '') { | ||
return ['site/page', ['url' => '/' . $pathInfo]]; | ||
} | ||
return false; // this rule does not apply | ||
} | ||
|
||
/** | ||
* @param UrlManager $manager | ||
* @param string $route | ||
* @param array<string, mixed> $params | ||
* @return bool|string | ||
*/ | ||
public function createUrl($manager, $route, $params) | ||
{ | ||
if ($route === 'site/page') { | ||
if (!empty($params['url'])) { | ||
return ltrim($params['url'], '/'); | ||
} | ||
} | ||
return false; // this rule does not apply | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace app\models; | ||
|
||
use yii\db\ActiveRecord; | ||
|
||
final class AdvertisementBadEmail extends ActiveRecord | ||
{ | ||
public static function tableName() | ||
{ | ||
return '{{advertisement_bad_email}}'; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public static function findRegexPatterns(): array | ||
{ | ||
return self::find() | ||
->select('regex_pattern') | ||
->where(['deleted' => null]) | ||
->column(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace app\models; | ||
|
||
use yii\db\ActiveRecord; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $url | ||
* @property string $title | ||
* @property string $abstract | ||
* @property string $content | ||
*/ | ||
final class Page extends ActiveRecord | ||
{ | ||
public static function findByUrl(string $url): ?self | ||
{ | ||
return self::find() | ||
->where(['url' => $url]) | ||
->one(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* @var yii\web\View $this | ||
* @var app\models\Page $page | ||
*/ | ||
|
||
use yii\helpers\Markdown; | ||
use app\widgets\Comments; | ||
use app\widgets\Hits; | ||
use app\widgets\Rating; | ||
use app\widgets\SocialBar; | ||
|
||
$this->title = $page->title; | ||
|
||
// TODO breadcrumbs | ||
|
||
?> | ||
|
||
<h1><?= $page->title ?></h1> | ||
<div class="markdown"><?= Markdown::process($page->content) ?></div> | ||
|
||
<?= Rating::widget(["tableName" => "page", "tableId" => $page->id]) ?> | ||
|
||
<?= SocialBar::widget(["id" => $page->id, "text" => $page->title]) ?> | ||
|
||
<?= Comments::widget(["tableName" => "page", "tableId" => $page->id]) ?> | ||
|
||
<?= Hits::widget(["tableName" => "page", "tableId" => $page->id]) ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters