Skip to content

Commit

Permalink
Merge pull request #117 from FriendsOfREDAXO/sync_canonical_url
Browse files Browse the repository at this point in the history
Canonical URL am (synchronisierten) Eintrag speichern können
  • Loading branch information
alxndr-w authored Sep 13, 2024
2 parents 3203c18 + 0a6eec1 commit 2322383
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
14 changes: 14 additions & 0 deletions install/tableset.json
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,20 @@
"not_required": "",
"no_db": "0",
"show_value": "1"
},
{
"table_name": "rex_neues_entry",
"prio": 25,
"type_id": "value",
"type_name": "showvalue",
"db_type": "varchar(191)",
"list_hidden": 1,
"search": 0,
"name": "canonical_url",
"label": "translate:neues_canonical_url",
"not_required": "",
"default": "",
"notice": "translate:neues_canonical_url_notice"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions install/update_scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
->ensureColumn(new rex_sql_column('updatedate', 'datetime'))
->ensureColumn(new rex_sql_column('updateuser', 'varchar(191)'))
->ensureColumn(new rex_sql_column('uuid', 'varchar(36)'))
->ensureColumn(new rex_sql_column('canonical_url', 'varchar(191)'))
->ensureIndex(new rex_sql_index('uuid', ['uuid'], rex_sql_index::UNIQUE))
->ensureIndex(new rex_sql_index('status', ['status']))
->ensureIndex(new rex_sql_index('publishdate', ['publishdate']))
Expand Down
2 changes: 2 additions & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ neues_description = Inhalt
neues_description_notice = Geben Sie den Inhalt Ihres News-Beitrags an.
neues_image = Titelbild
neues_images = Galerie
neues_canonical_url = Canonical URL
neues_canonical_url_notice = Gibt die Original-URL des News-Beitrags an, falls dieser Beitrag auf mehreren Websites veröffentlicht wurde.

neues_external_url = Externer Link
neues_external_url_notice = Gibt es weitere Informationen auf einer anderen Website, dann geben Sie hier die Adresse zu einer externen Website ein, z.B. <code>http://www.example.org/foo-bar/</code>
Expand Down
2 changes: 2 additions & 0 deletions lib/Cronjob/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public function createEntry(array $current): void
$entry->setValue('updateuser', 'neues_sync_cronjob');
$entry->setValue('createdate', $entry_data['createdate']);
$entry->setValue('updatedate', $entry_data['updatedate']);
// $category->setValue('canonical_url', $current['canonical_url']);

$entry->save();
}

Expand Down
34 changes: 31 additions & 3 deletions lib/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,36 @@ public function setExternalUrl(string $url): self
return $this;
}

/**
* Gibt die Canonical URL des Eintrags zurück.
* Returns the canonical URL of the entry.
*
* @return string|null Die Canonical URL des Eintrags oder null, wenn keine URL gesetzt ist. / The canonical URL of the entry or null if no URL is set.
*
* Beispiel / Example:
* $canonicalUrl = $entry->getCanonicalUrl();
*
* @api
*/
public function getCanonicalUrl(): ?string
{
return $this->getValue('canonical_url');
}

/**
* Setzt die Canonical URL des Eintrags.
* Sets the canonical URL of the entry.
*
* @param string $url Die neue Canonical URL des Eintrags. / The new canonical URL of the entry.
*
* @api
*/
public function setCanonicalUrl(string $url): self
{
$this->setValue('canonical_url', $url);
return $this;
}

/**
* Gibt das Veröffentlichungsdatum des Eintrags zurück.
* Returns the publish date of the entry.
Expand Down Expand Up @@ -558,9 +588,7 @@ public static function findByCategoryIds(string|array|null $category_ids = null,
$category_ids = explode(',', $category_ids);
}

// whereInList anwenden
// FIXME: whereInList gibt es nicht! Ist $query->whereListContains() gemeint?
$query->whereInList('category_ids', $category_ids);
$query->whereListContains('category_ids', $category_ids);
}

return $query->find();
Expand Down
8 changes: 8 additions & 0 deletions lib/neues.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use rex_pager;
use rex_sql;

use const ENT_QUOTES;

class Neues
{
/**
Expand Down Expand Up @@ -59,4 +61,10 @@ public static function getEntry(int $postId): string
$fragment->setVar('post', $post);
return $fragment->parse('neues/entry.php');
}

/* Hilfsklasse für JSON-LD Fragmente */
public static function htmlEncode($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8');
}
}

0 comments on commit 2322383

Please sign in to comment.