Added data classes bases, Trivial modifications to many files

Update .gitignore, .htaccess, and 19 more files...
This commit is contained in:
2024-01-07 07:34:50 +01:00
parent fac33dd5e2
commit 3891ec5859
20 changed files with 70 additions and 12 deletions

View File

@@ -0,0 +1,19 @@
<?php
// Making sure the file is included and not accessed directly.
if(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
header('HTTP/1.1 403 Forbidden');
die();
}
// Including required helpers.
include_once 'commons/langs.php';
// Including subclasses.
include_once 'commons/content/data/opengraph.php';
include_once 'commons/content/data/twitter_card.php';
class ContentMetadata {
}
?>

View File

@@ -0,0 +1,52 @@
<?php
// Making sure the file is included and not accessed directly.
if(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
header('HTTP/1.1 403 Forbidden');
die();
}
// Including required helpers.
include_once 'commons/langs.php';
class OpenGraphData {
public string $title;
public string $description;
public string $type;
public string $url;
public string $image;
public string $image_type;
function __construct(array $title, array $description, string $type, string $url, string $image,
string $image_type) {
global $default_language;
global $user_language;
$this->title = array_key_exists($user_language, $title) ? $title[$user_language] :
(array_key_exists($default_language, $title) ? $title[$default_language] : $title[0]);
$this->description = array_key_exists($user_language, $description) ? $description[$user_language] :
(array_key_exists($default_language, $description) ? $description[$default_language] : $description[0]);
$this->type = $type;
$this->url = $url;
$this->image = $image;
$this->image_type = $image_type;
}
static function from_json(array $json_data): ?OpenGraphData {
foreach(["title", "description", "type", "url", "image", "image_type"] as $wantedKey) {
if(!key_exists($wantedKey, $json_data)) {
return null;
}
}
return new OpenGraphData(
$json_data["title"],
$json_data["description"],
$json_data["type"],
$json_data["url"],
$json_data["image"],
$json_data["image_type"]
);
}
}
?>

View File

@@ -0,0 +1,20 @@
<?php
/*enum Suit {
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}*/
// See: https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup
/*class ContentTwitterMetadata {
public string $title;
public string $description;
public string $type;
public string $url;
public string $image;
public string $image_type;
}*/
?>