streams/Code/Module/Opensearch.php

57 lines
2.1 KiB
PHP
Raw Normal View History

2023-08-13 06:34:45 +00:00
<?php
namespace Code\Module;
use App;
use Code\Web\Controller;
use Code\Lib\System;
use Code\Render\Theme;
use Code\Lib\Channel;
class Opensearch extends Controller {
function init() {
// stock project icons are 64px which is required for this interface
// custom site icons will normally be [ 300,80,48 ] px.
// Detect which one of these is in play and rewrite custom icon urls
// so to generate a 64px icon on demand
$icon = System::get_site_icon();
$channel = null;
if (!str_contains($icon, z_root() . '/image')) {
$icon = str_replace('/m/','/64/',$icon);
}
if (argc() > 1) {
$channel = Channel::from_username(argv(1));
if (!$channel) {
killme();
}
}
header("Content-type: application/opensearchdescription+xml");
if($channel) {
2023-08-13 07:43:30 +00:00
$html = replace_macros(Theme::get_template('opensearch.tpl'), [
2023-08-13 06:34:45 +00:00
'$project' => xmlify($channel['channel_address'] . '@' . App::get_hostname()),
'$search_project' => xmlify(t('Search $Projectname') . '|' . $channel['channel_address'] . '@' . App::get_hostname()),
2023-08-29 21:54:37 +00:00
'$searchurl' => xmlify(zid(z_root() . '/search/' . $channel['channel_address'] . '?search={searchTerms}')),
2023-08-13 06:34:45 +00:00
'$aptype' => xmlify('application/ld+json; profile="https://www.w3.org/ns/activitystreams"'),
'$photo' => xmlify($channel['xchan_photo_s']),
]);
}
else {
2023-08-13 07:43:30 +00:00
$html = replace_macros(Theme::get_template('opensearch.tpl'), [
2023-08-13 06:34:45 +00:00
'$project' => xmlify(App::get_hostname()),
'$search_project' => xmlify(t('Search $Projectname') . '|' . App::get_hostname()),
2023-08-29 21:54:37 +00:00
'$searchurl' => xmlify(zid(z_root() . '/search?search={searchTerms}')),
2023-08-13 06:34:45 +00:00
'$aptype' => xmlify('application/ld+json; profile="https://www.w3.org/ns/activitystreams"'),
2023-08-29 21:54:37 +00:00
'$photo' => xmlify($icon),
2023-08-13 06:34:45 +00:00
]);
}
echo $html;
killme();
}
}