Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erste Überarbeitung mit RexStan #90

Merged
merged 4 commits into from
Aug 19, 2024
Merged
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
12 changes: 6 additions & 6 deletions fragments/neues/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<?= $post->getFormattedPublishDate() ?>

<!-- Author -->
<?php if ($post->getAuthor()) : ?>
<?php if ($post->getAuthor()->getName()) : ?>
<?php if (null !== $post->getAuthor()) : ?>
<?php if (null !== $post->getAuthor()->getName()) : ?>
von <span><?= htmlspecialchars($post->getAuthor()->getName()) ?></span>
<?php elseif($post->getAuthor()->getNickname()): ?>
<?php elseif(null !== $post->getAuthor()->getNickname()): ?>
von <span><?= htmlspecialchars($post->getAuthor()->getNickname()) ?></span>
<?php endif ?>
<?php endif ?>
Expand All @@ -40,7 +40,7 @@
<?php
$media = rex_media::get($post->getImage());
?>
<?php if ($media) : ?>
<?php if (null !== $media) : ?>
<div class="ratio ratio-16x9 mb-3 mt-4">
<img src="<?= $media->getUrl() ?>" alt="<?= htmlspecialchars($media->getTitle()) ?>" class="h-100 object-fit-cover" width="200"/>
</div>
Expand All @@ -49,7 +49,7 @@


<!-- Post Content -->
<?php if ($post->getDescription()) : ?>
<?php if ('' !== $post->getDescription()) : ?>
<div class="mt-5">
<?= $post->getDescription() ?>
</div>
Expand All @@ -63,7 +63,7 @@
$media = rex_media::get($image);
$mediaUrl = rex_media_manager::getUrl('rex_media_medium', $image);
?>
<?php if ($media) : ?>
<?php if (null !== $media) : ?>
<div class="col-md-4">
<a href="<?= $media->getUrl() ?>" class="d-inline-flex ratio ratio-16x9 h-100">
<img src="<?= $mediaUrl ?>" alt="<?= htmlspecialchars($media->getTitle()) ?>" class="h-100 object-fit-cover" width="200"/>
Expand Down
7 changes: 4 additions & 3 deletions fragments/neues/list-entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<div class="col p-4 d-flex flex-column position-static">

<!-- Categories -->
<?php if ($post->getCategories()) : ?>
<?php // TODO: Doppelte Abrufe aus der DB sind Mist!?>
<?php if (0 < count($post->getCategories())) : ?>
<p class="d-inline-block mb-2 text-primary-emphasis">
<?= htmlspecialchars(implode(', ', $post->getCategories()->toKeyValue('id', 'name'))) ?>
</p>
Expand All @@ -26,7 +27,7 @@
<?php endif ?>

<!-- Date -->
<?php if ($post->getPublishDate()) : ?>
<?php if ('' < $post->getPublishDate()) : ?>
<div class="mb-2 text-body-secondary">
<?= $post->getFormattedPublishDate() ?>
</div>
Expand All @@ -46,7 +47,7 @@
$media = rex_media::get($post->getImage());
$mediaUrl = rex_media_manager::getUrl('rex_media_medium', $post->getImage());
?>
<?php if ($media) : ?>
<?php if (null !== $media) : ?>
<div class="col-auto d-none d-lg-block">
<img src="<?= $mediaUrl ?>" alt="<?= htmlspecialchars($media->getTitle()) ?>" class="h-100 object-fit-cover" width="200"/>
</div>
Expand Down
21 changes: 12 additions & 9 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
use rex_sql;
use rex_yform_manager_table_api;

use function count;

$sql = rex_sql::factory();

/* Tablesets aktualisieren */
if (rex_addon::get('yform') && rex_addon::get('yform')->isAvailable()) {
if (rex_plugin::get('yform', 'manager')->isAvailable()) {
rex_yform_manager_table_api::importTablesets(rex_file::get(__DIR__ . '/install/tableset.json'));

// Vorhandene leere UUID-Felder aktualisieren
$sql = rex_sql::factory();
$sql->setQuery('UPDATE ' . rex::getTable('neues_author') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
$sql->setQuery('UPDATE ' . rex::getTable('neues_category') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');
$sql->setQuery('UPDATE ' . rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""');

require_once __DIR__ . '/install/update_scheme.php';
}

if (!rex_media::get('neues_entry_fallback_image.png')) {
if (null === rex_media::get('neues_entry_fallback_image.png')) {
rex_file::copy(__DIR__ . '/install/neues_entry_fallback_image.png', rex_path::media('neues_entry_fallback_image.png'));
$data = [];
$data['title'] = 'Aktuelles - Fallback-Image';
Expand All @@ -40,7 +43,7 @@
}

/* Cronjob installieren */
if (rex_addon::get('cronjob') && rex_addon::get('cronjob')->isAvailable()) {
if (rex_addon::get('cronjob')->isAvailable()) {
$cronjobPublish = 'FriendsOfRedaxo\\Neues\\Cronjob\\Publish';

/**
Expand All @@ -67,16 +70,16 @@
}

/* URL-Profile installieren */
if (rex_addon::get('url') && rex_addon::get('url')->isAvailable()) {
if (rex_addon::get('url')->isAvailable()) {
if (false === rex_config::get('neues', 'url_profile', false)) {
$rex_neues_category = array_filter(rex_sql::factory()->getArray("SELECT * FROM rex_url_generator_profile WHERE `table_name` = '1_xxx_rex_neues_category'"));
if (!$rex_neues_category) {
$query = str_replace('999999', rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_category.sql'));
if (0 < count($rex_neues_category)) {
$query = str_replace('999999', (string) rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_category.sql'));
rex_sql::factory()->setQuery($query);
}
$rex_neues_entry = array_filter(rex_sql::factory()->getArray("SELECT * FROM rex_url_generator_profile WHERE `table_name` = '1_xxx_rex_neues_entry'"));
if (!$rex_neues_entry) {
$query = str_replace('999999', rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_entry.sql'));
if (0 < count($rex_neues_entry)) {
$query = str_replace('999999', (string) rex_article::getSiteStartArticleId(), rex_file::get(__DIR__ . '/install/rex_url_profile_neues_entry.sql'));
rex_sql::factory()->setQuery($query);
}
/* URL-Profile wurden bereits einmal installiert, daher nicht nochmals installieren und Entwickler-Einstellungen respektieren */
Expand Down
31 changes: 26 additions & 5 deletions lib/Api/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use FriendsOfRedaxo\Neues\Entry;
use rex;
use rex_api_function;
use rex_api_result;
use rex_clang;
use rex_path;
use rex_response;
Expand All @@ -17,7 +18,11 @@ class Rss extends rex_api_function
{
protected $published = true; // Erlaubt den Aufruf aus dem Frontend

public function execute(): void
/**
* @return never
* @api
*/
public function execute(): rex_api_result
{
$domain_id = rex_request('domain_id', 'int', null);
$lang_id = rex_request('lang_id', 'int', null);
Expand All @@ -41,17 +46,32 @@ public function execute(): void
exit;
}

public static function getRssFeed($collection, $domain, $lang, $description, $filename)
/**
* @param rex_yform_manager_collection<Entry> $collection
* @api
*
* TODO: Parameter Domain wird nicht benutzt: Klären ob der weg kann. Type fehlt
*/
public static function getRssFeed($collection, $domain, int $lang, string $description, string $filename): string|bool
{
return self::createRssFeed($collection, $domain, $lang, $description, $filename);
}

public static function joinUrls($url1, $url2)
/**
* @api
*/
public static function joinUrls(string $url1, string $url2): string
{
return rtrim($url1, '/') . '/' . ltrim($url2, '/');
}

public static function createRssFeed(rex_yform_manager_collection $collection, $domain, $lang, $description, $filename = 'rss.neues.xml')
/**
* @param rex_yform_manager_collection<Entry> $collection
* @api
*
* TODO: Parameter Domain wird nicht benutzt: Klären ob der weg kann. Type fehlt
*/
public static function createRssFeed(rex_yform_manager_collection $collection, $domain, int $lang, string $description, string $filename = 'rss.neues.xml'): string|bool
{
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"></rss>');

Expand All @@ -60,12 +80,13 @@ public static function createRssFeed(rex_yform_manager_collection $collection, $
$channel->addChild('description', $description);
$channel->addChild('link', rex::getServer());

// RexStan: Only booleans are allowed in &&, int given on the left side.
// TODO: klären was der Teil `$lang &&` bewirken soll und ggf. rauswerfen
if ($lang && $lang > 0) {
$channel->addChild('language', rex_clang::get($lang)->getCode());
}

foreach ($collection as $entry) {
/** @var neues_entry $entry */
$item = $channel->addChild('item');
$item->addChild('title', htmlspecialchars($entry->getName()));
$item->addChild('description', htmlspecialchars(strip_tags($entry->getDescription())));
Expand Down
4 changes: 2 additions & 2 deletions lib/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public function setName(string $name): self
* Gibt die Einträge der Kategorie zurück.
* Returns the entries of the Category.
*
* @return rex_yform_manager_collection|null Die Einträge der Kategorie oder null, wenn keine Einträge vorhanden sind. / The entries of the Category or null if no entries are present.
* @return rex_yform_manager_collection<Entry> Die Einträge der Kategorie oder null, wenn keine Einträge vorhanden sind. / The entries of the Category or null if no entries are present.
*
* Beispiel / Example:
* $entries = $category->getEntries();
*
* @api
*/
public function getEntries(): ?rex_yform_manager_collection
public function getEntries(): rex_yform_manager_collection
{
return $this->getRelatedCollection('date_id');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Cronjob/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
use rex_cronjob;
use rex_i18n;
use rex_socket;
use rex_socket_response;

class Sync extends rex_cronjob
{
/** @var array<string,string> */
private $rest_urls = ['category' => '/rest/neues/category/5.0.0/',
'author' => '/rest/neues/author/5.0.0/',
'entry' => '/rest/neues/entry/5.0.0/'];
Expand Down
30 changes: 14 additions & 16 deletions lib/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use rex_media_plus;
use rex_url;
use rex_yform;
use rex_yform_list;
use rex_yform_manager_collection;
use rex_yform_manager_dataset;
use rex_yform_manager_table;
Expand Down Expand Up @@ -76,9 +77,9 @@ public function setName(string $name): self
/**
* YFORM_DATA_LIST: passt die Listendarstellung an.
*
* @api
* @param rex_extension_point<rex_yform_list> $ep
* @return void|rex_yform_list
* @api
*/
public static function epYformDataList(rex_extension_point $ep)
{
Expand Down Expand Up @@ -142,7 +143,7 @@ static function ($a) {
* Gibt den Autor des Eintrags zurück.
* Returns the author of the entry.
*
* @return neues_author|null Der Autor des Eintrags oder null, wenn kein Autor gesetzt ist. / The author of the entry or null if no author is set.
* @return Author|null Der Autor des Eintrags oder null, wenn kein Autor gesetzt ist. / The author of the entry or null if no author is set.
*
* Beispiel / Example:
* $author = $entry->getAuthor();
Expand Down Expand Up @@ -199,14 +200,14 @@ public function getTeaser(): string
* Gibt die Kategorien des Eintrags zurück.
* Returns the categories of the entry.
*
* @return rex_yform_manager_collection|null Die Kategorien des Eintrags oder null, wenn keine Kategorien gesetzt sind. / The categories of the entry or null if no categories are set.
* @return rex_yform_manager_collection<Category> Die Kategorien des Eintrags oder eine leere Liste. / The categories of the entry or an empty list.
*
* Beispiel / Example:
* $categories = $entry->getCategories();
*
* @api
*/
public function getCategories(): ?rex_yform_manager_collection
public function getCategories(): rex_yform_manager_collection
{
return $this->getRelatedCollection('category_ids');
}
Expand Down Expand Up @@ -254,7 +255,7 @@ public function setImage(string $image): self
*
* Beispiel / Example:
* $images = $entry->getImages();
*
* TODO: null kommt nicht vor
* @api
*/
public function getImages(): ?array
Expand Down Expand Up @@ -488,16 +489,16 @@ public function setStatus(int $status): self
* Finds online entries. If a Category ID is provided, only entries from this Category are returned.
*
* @param int|null $category_id Die ID der Kategorie. / The ID of the Category.
* @return rex_yform_manager_collection|null Die gefundenen Einträge oder null, wenn keine Einträge gefunden wurden. / The found entries or null if no entries were found.
* @return rex_yform_manager_collection<static> Die gefundenen Einträge bzw. eine leere Liste. / The found entries or empty list.
*
* Beispiel / Example:
* $entries = FriendsOfRedaxo\Neues\Entry::findOnline(1);
*
* @api
*/
public static function findOnline(?int $category_id = null): ?rex_yform_manager_collection
public static function findOnline(?int $category_id = null): rex_yform_manager_collection
{
if ($category_id) {
if (null !== $category_id) {
return self::findByCategory($category_id);
}
return self::query()->where('status', 1, '>=')->find();
Expand All @@ -509,14 +510,14 @@ public static function findOnline(?int $category_id = null): ?rex_yform_manager_
*
* @param int|null $category_id Die ID der Kategorie. / The ID of the Category.
* @param int $status Der Status der Einträge. / The status of the entries.
* @return rex_yform_manager_collection|null Die gefundenen Einträge oder null, wenn keine Einträge gefunden wurden. / The found entries or null if no entries were found.
* @return rex_yform_manager_collection<static> Die gefundenen Einträge bzw. eine leere Liste. / The found entries or empty list.
*
* Beispiel / Example:
* $entries = FriendsOfRedaxo\Neues\Entry::findByCategory(1, 1);
*
* @api
*/
public static function findByCategory(?int $category_id = null, int $status = 1): ?rex_yform_manager_collection
public static function findByCategory(?int $category_id = null, int $status = 1): rex_yform_manager_collection
{
$query = self::query();
$alias = $query->getTableAlias();
Expand All @@ -530,14 +531,14 @@ public static function findByCategory(?int $category_id = null, int $status = 1)
*
* @param string|array|null $category_ids Die IDs der Kategorien als String oder Array. / The IDs of the Categories as a String or Array.
* @param int $status Der Status der Einträge. / The status of the entries.
* @return rex_yform_manager_collection|null Die gefundenen Einträge oder null, wenn keine Einträge gefunden wurden. / The found entries or null if no entries were found.
* @return rex_yform_manager_collection<static> Die gefundenen Einträge bzw. eine leere Liste. / The found entries or empty list.
*
* Beispiel / Example:
* $entries = FriendsOfRedaxo\Neues\Entry::findByCategoryIds('1,2', 1);
*
* @api
*/
public static function findByCategoryIds(string|array|null $category_ids = null, int $status = 1): ?rex_yform_manager_collection
public static function findByCategoryIds(string|array|null $category_ids = null, int $status = 1): rex_yform_manager_collection
{
$query = self::query()->where('status', $status, '>=');

Expand Down Expand Up @@ -568,9 +569,6 @@ public static function findByCategoryIds(string|array|null $category_ids = null,
*/
public function getUrl(string $profile = 'neues-entry-id'): string
{
if ($url = rex_getUrl(null, null, [$profile => $this->getId()])) {
return $url;
}
return '';
return rex_getUrl(null, null, [$profile => $this->getId()]);
}
}
2 changes: 1 addition & 1 deletion lib/EntryLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EntryLang extends rex_yform_manager_dataset
* Gibt die News-Einträge der aktuellen Sprache zurück.
* Returns the entries of the language.
*
* @return rex_yform_manager_collection|null Die Einträge der Sprache oder null, wenn keine Einträge gefunden wurden. / The entries of the language or null if no entries were found.
* @return rex_yform_manager_collection<Entry> Die Einträge der Sprache oder null, wenn keine Einträge gefunden wurden. / The entries of the language or null if no entries were found.
christophboecker marked this conversation as resolved.
Show resolved Hide resolved
*
* Beispiel / Example:
* $entries = $language->getEntries();
Expand Down
4 changes: 4 additions & 0 deletions lib/neues.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Neues
*
* Beispiel / Example:
* echo neues::getList(2);
*
* @api
*/
public static function getList(int $rowsPerPage = 10, string $pageCursor = 'page'): string
{
Expand All @@ -47,6 +49,8 @@ public static function getList(int $rowsPerPage = 10, string $pageCursor = 'page
*
* Beispiel / Example:
* echo neues::getEntry(2);
*
* @api
*/
public static function getEntry(int $postId): string
{
Expand Down
Loading