Lettersail: online English school for kids on MODX 3 (templates, chunks, snippets, plugins, scripts)
This commit is contained in:
commit
3799cf8de5
96 files changed
+4423
No files matched your search
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
$language = (string) $modx->getOption('cultureKey', null, 'ru');
|
||||
$homeId = (int) $modx->getOption('site_start');
|
||||
$siteUrl = (string) $modx->makeUrl($homeId, '', '', 'full');
|
||||
$rootUrl = 'https://' . $modx->getOption('http_host') . '/';
|
||||
$words = [];
|
||||
foreach (['trial', 'trial_text', 'plan', 'per_month', 'course', 'teaches', 'job', 'catalog'] as $wordKey) {
|
||||
$words[$wordKey] = (string) $modx->lexicon('ls_schema_' . $wordKey);
|
||||
}
|
||||
|
||||
$list = static function (string $tv) use ($modx, $homeId): array {
|
||||
$modx->runSnippet('getImageList', ['tvname' => $tv, 'docid' => $homeId, 'toJsonPlaceholder' => 'ls_schema_list']);
|
||||
return json_decode((string) $modx->getPlaceholder('ls_schema_list'), true) ?: [];
|
||||
};
|
||||
$text = static fn(string $value): string => trim(preg_replace('/\s+/u', ' ', strip_tags($value)));
|
||||
|
||||
$home = $modx->getObject(modResource::class, $homeId);
|
||||
$name = 'Lettersail';
|
||||
$description = $text((string) $home->get('description'));
|
||||
$title = $text((string) ($home->get('longtitle') ?: $home->get('pagetitle')));
|
||||
|
||||
$offers = [];
|
||||
foreach ($list('prices') as $row) {
|
||||
$offers[] = [
|
||||
'@type' => 'Offer',
|
||||
'@id' => $siteUrl . '#offer-' . $row['MIGX_id'],
|
||||
'name' => $words['plan'] . $text($row['title']),
|
||||
'description' => $text($row['price'] . $words['per_month'] . $row['text']),
|
||||
'priceSpecification' => [
|
||||
'@type' => 'UnitPriceSpecification',
|
||||
'price' => (int) $row['price'],
|
||||
'priceCurrency' => 'PLN',
|
||||
'unitCode' => 'MON',
|
||||
],
|
||||
];
|
||||
}
|
||||
array_unshift($offers, [
|
||||
'@type' => 'Offer',
|
||||
'@id' => $siteUrl . '#offer-trial',
|
||||
'name' => $words['trial'],
|
||||
'description' => $words['trial_text'],
|
||||
'price' => 0,
|
||||
'priceCurrency' => 'PLN',
|
||||
]);
|
||||
|
||||
$courses = [];
|
||||
foreach ($list('programs') as $index => $row) {
|
||||
$age = $text($row['title']);
|
||||
[$min, $max] = array_map('intval', explode('-', $age) + [1 => 0]);
|
||||
$courses[] = [
|
||||
'@type' => 'Course',
|
||||
'name' => sprintf($words['course'], $age),
|
||||
'description' => $text($row['text']),
|
||||
'teaches' => $words['teaches'],
|
||||
'timeRequired' => 'PT45M',
|
||||
'audience' => ['@type' => 'PeopleAudience', 'suggestedMinAge' => $min, 'suggestedMaxAge' => $max],
|
||||
'hasCourseInstance' => ['@type' => 'CourseInstance', 'courseMode' => 'online', 'maximumAttendeeCapacity' => 6],
|
||||
'offers' => $index === 0 ? $offers : array_map(static fn(array $offer): array => ['@id' => $offer['@id']], $offers),
|
||||
];
|
||||
}
|
||||
|
||||
$teachers = [];
|
||||
foreach ($list('teachers') as $row) {
|
||||
$teachers[] = [
|
||||
'@type' => 'Person',
|
||||
'name' => $text($row['title']),
|
||||
'jobTitle' => $words['job'] . ($language === 'ru' ? $text($row['age']) : lcfirst($text($row['age']))),
|
||||
'description' => $text($row['text']),
|
||||
'image' => $rootUrl . ltrim((string) $row['photo'], '/'),
|
||||
];
|
||||
}
|
||||
|
||||
$reviews = [];
|
||||
foreach ($list('reviews') as $row) {
|
||||
$reviews[] = [
|
||||
'@type' => 'Review',
|
||||
'author' => ['@type' => 'Person', 'name' => $text($row['title'])],
|
||||
'reviewBody' => $text($row['text']),
|
||||
'reviewRating' => ['@type' => 'Rating', 'ratingValue' => (int) $row['rating'], 'bestRating' => 5, 'worstRating' => 1],
|
||||
];
|
||||
}
|
||||
|
||||
$questions = [];
|
||||
foreach ($list('faq') as $row) {
|
||||
$questions[] = [
|
||||
'@type' => 'Question',
|
||||
'name' => $text($row['title']),
|
||||
'acceptedAnswer' => ['@type' => 'Answer', 'text' => $text($row['text'])],
|
||||
];
|
||||
}
|
||||
|
||||
$school = [
|
||||
'@type' => 'EducationalOrganization',
|
||||
'@id' => $siteUrl . '#school',
|
||||
'name' => $name,
|
||||
'url' => $siteUrl,
|
||||
'description' => $description,
|
||||
'logo' => ['@type' => 'ImageObject', 'url' => $rootUrl . 'assets/site/icon-512.png', 'width' => 512, 'height' => 512],
|
||||
'contactPoint' => [
|
||||
'@type' => 'ContactPoint',
|
||||
'contactType' => 'customer support',
|
||||
'email' => (string) $modx->getOption('ls_contact_email'),
|
||||
'availableLanguage' => $language,
|
||||
],
|
||||
'knowsLanguage' => array_values(array_unique(['en', $language])),
|
||||
'hasOfferCatalog' => ['@type' => 'OfferCatalog', 'name' => $words['catalog'], 'itemListElement' => $courses],
|
||||
'employee' => $teachers,
|
||||
'review' => $reviews,
|
||||
];
|
||||
|
||||
$blocks = [
|
||||
[
|
||||
'@type' => 'WebPage',
|
||||
'@id' => $siteUrl . '#webpage',
|
||||
'url' => $siteUrl,
|
||||
'name' => $title,
|
||||
'description' => $description,
|
||||
'inLanguage' => $language,
|
||||
'mainEntity' => $school,
|
||||
],
|
||||
[
|
||||
'@type' => 'WebSite',
|
||||
'@id' => $siteUrl . '#website',
|
||||
'url' => $siteUrl,
|
||||
'name' => $name,
|
||||
'inLanguage' => $language,
|
||||
],
|
||||
[
|
||||
'@type' => 'FAQPage',
|
||||
'@id' => $siteUrl . '#faq',
|
||||
'inLanguage' => $language,
|
||||
'mainEntity' => $questions,
|
||||
],
|
||||
];
|
||||
|
||||
$output = '';
|
||||
foreach ($blocks as $block) {
|
||||
$output .= '<script type="application/ld+json">' . json_encode(['@context' => 'https://schema.org'] + $block, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG) . "</script>\n";
|
||||
}
|
||||
return $output;
|
||||
Reference in new issue
Block a user