From ed57c386db34d8693ca75311972d0929ebe5f488 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 01 Jun 2026 22:23:19 +0000
Subject: [PATCH] =Added some more Schema classes, allowed for override of array in outputSchema for complex schema, as for timeline post types
---
inc/registrar/config/seo/Meta.php | 66 ++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 1 deletions(-)
diff --git a/inc/registrar/config/seo/Meta.php b/inc/registrar/config/seo/Meta.php
index 7e34b0b..26a4ac9 100644
--- a/inc/registrar/config/seo/Meta.php
+++ b/inc/registrar/config/seo/Meta.php
@@ -11,13 +11,23 @@
protected string $slug;
protected string $title;
+ protected array $titleConfig = [
+ 'maxLength' => 60,
+ 'alts' => []
+ ];
protected string $description;
+ protected array $descriptionConfig = [
+ 'maxLength' => 120,
+ 'alts' => []
+ ];
protected int $image;
protected int $twitterImage;
public function __construct(string $slug) {
$this->slug = $slug;
+
+ $this->titleConfig['alts'] = apply_filters(BASE.jvbNoBase($slug).'TitleAlts', []);
add_action('init', [$this, 'init']);
}
@@ -36,6 +46,27 @@
}
}
+ public function setAlts(array $alts, string $type = 'title'):void
+ {
+ foreach (array_values($alts) as $i => $alt) {
+ if (!is_string($alt)) {
+ error_log('[Registrar.config.Meta]:setAlts invalid string attempted: '.print_r($alt, true));
+ unset($alts[$i]);
+ }
+ }
+ switch ($type) {
+ case 'title':
+ $this->titleConfig['alts'] = $alts;
+ break;
+ case 'description':
+ $this->descriptionConfig['alts'] = $alts;
+ break;
+ default:
+ error_log('[Registrar.config.Meta]:setAlts invalid type attempted: '.print_r($type, true));
+
+ }
+ }
+
public function hasTitle():bool
{
return !empty($this->title);
@@ -53,6 +84,37 @@
return !empty($this->twitterImage);
}
+ public function testLength(int $ID, string $result, string $type):string
+ {
+ $maxLength = match($type) {
+ 'title' => $this->titleConfig['maxLength'],
+ 'description' => $this->descriptionConfig['alts'],
+ default => false
+ };
+ if (!$maxLength) {
+ error_log('[Registrar.config.Meta]:testLength invalid type: '.$type);
+ return $result;
+ }
+ $alts = match($type) {
+ 'title' => $this->titleConfig['alts'],
+ 'description' => $this->descriptionConfig['alts'],
+ };
+
+
+ usort($alts, fn($a, $b) => mb_strlen($b) <=> mb_strlen($a));
+
+
+ $meta = new \JVBase\meta\Meta($ID, Registrar::getInstance($this->slug)->getType());
+ foreach ($alts as $alt) {
+ $alt = Resolver::resolve($alt, $meta);
+ $r = $result.' '.trim($alt);
+ if (mb_strlen($r) <= $maxLength) {
+ return $r;
+ }
+ }
+ return rtrim($result, $maxLength - 3).'...';
+ }
+
public function filterTitle(string $title, ?array $args): string
{
error_log('Filtering title...');
@@ -63,7 +125,9 @@
$meta = new \JVBase\meta\Meta($ID, Registrar::getInstance($this->slug)->getType());
- return Resolver::resolve($this->title, $meta);
+ $resolved = Resolver::resolve($this->title, $meta);
+ $resolved = $this->testLength($ID, $resolved, 'title');
+ return $resolved;
}
public function filterDescription(string $description, ?array $args): string
--
Gitblit v1.10.0