more overdue adaptations

This commit is contained in:
Matthew Exon 2023-12-26 15:52:57 +01:00
parent f783b4857d
commit 2cf1076d5c
2 changed files with 23 additions and 32 deletions

View file

@ -840,12 +840,10 @@ function retriever_transform_images(array &$item, array $resource) {
/**
* @brief Displays the retriever configuration page for a contact. Alternatively, if the user clicked the "help" button, display the help content.
*
* @param App $a The App object
*/
function retriever_content(App $a) {
function retriever_content() {
if (!DI::userSession()->getLocalUserId()) {
$a->page['content'] .= "<p>Please log in</p>";
DI::page()['content'] .= "<p>Please log in</p>";
return;
}
if (isset(DI::args()->getArgv()[1]) and DI::args()->getArgv()[1] === 'help') {
@ -854,7 +852,7 @@ function retriever_content(App $a) {
$feeds[$i]['url'] = DI::baseUrl() . '/retriever/' . $feeds[$i]['id'];
}
$template = Renderer::getMarkupTemplate('/help.tpl', 'addon/retriever/');
$a->page['content'] .= Renderer::replaceMacros($template, array(
DI::page()['content'] .= Renderer::replaceMacros($template, array(
'$config' => DI::baseUrl() . '/settings/addon',
'$allow_images' => DI::config()->get('retriever', 'allow_images'),
'$feeds' => $feeds));
@ -895,12 +893,12 @@ function retriever_content(App $a) {
}
}
DBA::update('retriever_rule', ['data' => json_encode($retriever_rule['data'])], ['id' => intval($retriever_rule["id"])], ['data' => '']);
$a->page['content'] .= "<p><b>Settings Updated";
DI::page()['content'] .= "<p><b>Settings Updated";
if (!empty($_POST["retriever_retrospective"])) {
apply_retrospective($retriever_rule, $_POST["retriever_retrospective"]);
$a->page['content'] .= " and retrospectively applied to " . $_POST["retriever_retrospective"] . " posts";
DI::page()['content'] .= " and retrospectively applied to " . $_POST["retriever_retrospective"] . " posts";
}
$a->page['content'] .= ".</p></b>";
DI::page()['content'] .= ".</p></b>";
}
$template = Renderer::getMarkupTemplate('/rule-config.tpl', 'addon/retriever/');
@ -1011,12 +1009,11 @@ function retriever_post_remote_hook(array &$item) {
/**
* @brief Hook for adding per-user retriever settings to the user's settings page
*
* @param App $a The App object (by ref)
* @param string $s HTML string to which to append settings content (by ref)
* @param array $data Hook data array
*/
function retriever_addon_settings(App &$a, string &$s) {
$all_photos = DI::config()->get(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos');
$oembed = DI::config()->get(DI::userSession()->getLocalUserId(), 'retriever', 'oembed');
function retriever_addon_settings(array &$data) {
$all_photos = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos');
$oembed = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'retriever', 'oembed');
$template = Renderer::getMarkupTemplate('/settings.tpl', 'addon/retriever/');
$config = array('$submit' => DI::l10n()->t('Save Settings'),
'$title' => DI::l10n()->t('Retriever Settings'),
@ -1030,26 +1027,31 @@ function retriever_addon_settings(App &$a, string &$s) {
DI::l10n()->t('Resolve OEmbed'),
$oembed,
DI::l10n()->t('Check this to attempt to retrieve embedded content for all posts'));
$s .= Renderer::replaceMacros($template, $config);
$html = Renderer::replaceMacros($template, $config);
$data = [
'addon' => 'retriever',
'title' => DI::l10n()->t('Retriever Settings'),
'html' => $html,
];
}
/**
* @brief Hook for processing post results from user's settings page
*
* @param App $a The App object
* @param array $post Posted content
* @return void
*/
function retriever_addon_settings_post(App $a, array $post) {
function retriever_addon_settings_post(array $post) {
if ($post['retriever_all_photos']) {
DI::config()->set(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos', $post['retriever_all_photos']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos', $post['retriever_all_photos']);
}
else {
DI::config()->delete(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos');
DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos');
}
if ($post['retriever_oembed']) {
DI::config()->set(DI::userSession()->getLocalUserId(), 'retriever', 'oembed', $post['retriever_oembed']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'retriever', 'oembed', $post['retriever_oembed']);
}
else {
DI::config()->delete(DI::userSession()->getLocalUserId(), 'retriever', 'oembed');
DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'retriever', 'oembed');
}
}

View file

@ -1,16 +1,5 @@
<span id="settings_retriever_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose('settings_retriever_expanded'); openClose('settings_retriever_inflated');">
<h3>{{$title}}</h3>
</span>
<div id="settings_retriever_expanded" class="settings-block" style="display: none;">
<span class="fakelink" onclick="openClose('settings_retriever_expanded'); openClose('settings_retriever_inflated');">
<h3>{{$title}}</h3>
</span>
<p>
<a href="{{$help}}">Get Help</a>
</p>
<p><a href="{{$help}}">Get Help</a></p>
{{if $allow_images}}
{{include file="field_checkbox.tpl" field=$allphotos}}
{{/if}}
{{include file="field_checkbox.tpl" field=$oembed}}
<input type="submit" value="{{$submit}}">
</div>