Compare commits

..

No commits in common. "06b1f4b495dc83ecadc16f2f7bc084a9fc67ba3e" and "cc4951f515ff17a054877312ec96a63db81e3993" have entirely different histories.

4 changed files with 11 additions and 21 deletions

View File

@ -1,22 +1,12 @@
<?php <?php
class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController { class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController {
public function kagiStringsAction() {
$this->view->kagi_strings = json_encode(array(
'loading_summary' => _t('ext.kagiSummarizer.ui.loading_summary'),
'error' => _t('ext.kagiSummarizer.ui.error')
));
$this->view->_layout(false);
$this->view->_path('kagiSummarizer/strings.js');
header('Content-Type: application/javascript; charset=UTF-8');
}
public function summarizeAction() { public function summarizeAction() {
$this->view->_layout(false); $this->view->_layout(false);
$kagi_token = FreshRSS_Context::$user_conf->kagi_token; $kagi_token = FreshRSS_Context::$user_conf->kagi_token;
if ($kagi_token === null || trim($kagi_token) === '') { if ($kagi_token === null || trim($kagi_token) ==='') {
echo json_encode(array( echo json_encode(array(
'response' => array( 'response' => array(
'output_text' => _t('ext.kagiSummarizer.ui.no_token_configured'), 'output_text' => _t('ext.kagiSummarizer.ui.no_token_configured'),
@ -44,10 +34,14 @@ class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController {
'Authorization: ' . $kagi_token 'Authorization: ' . $kagi_token
)); ));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
$response = curl_exec($curl); $response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$response_body = substr($response, $header_size);
echo json_encode(array( echo json_encode(array(
'response' => json_decode($response), 'response' => json_decode($response_body),
'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE) 'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE)
)); ));
} }

View File

@ -5,8 +5,6 @@ class KagiSummarizerExtension extends Minz_Extension {
$this->registerTranslates(); $this->registerTranslates();
$this->registerHook('entry_before_display', [$this, 'addSummarizeButton']); $this->registerHook('entry_before_display', [$this, 'addSummarizeButton']);
Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, false, false); Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, false, false);
Minz_View::appendScript(_url('kagiSummarizer', 'kagiStrings'), false, true, false);
$this->registerViews();
$this->registerController('kagiSummarizer'); $this->registerController('kagiSummarizer');
} }
@ -32,10 +30,7 @@ class KagiSummarizerExtension extends Minz_Extension {
'params' => array( 'params' => array(
'id' => $entry->id() 'id' => $entry->id()
))); )));
$entry->_content( $entry->_content('<p class="kagi-summary"><a data-loading="' . htmlspecialchars(_t('ext.kagiSummarizer.ui.loading_summary')) . '" data-error="' . htmlspecialchars(_t('ext.kagiSummarizer.ui.error')) . '" class="btn" href="' . $url .'">' . _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>' . $entry->content());
'<p class="kagi-summary"><a class="btn" href="' . $url .'">'
. _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>'
. $entry->content());
return $entry; return $entry;
} }
} }

View File

@ -21,11 +21,13 @@ function configureSummarizeButtons() {
function summarizeButtonClick(button) { function summarizeButtonClick(button) {
var url = button.href; var url = button.href;
var loadingMsg = button.dataset.loading;
var errorMsg = button.dataset.error;
var container = button.parentNode; var container = button.parentNode;
container.classList.add('alert'); container.classList.add('alert');
container.classList.add('alert-warn'); container.classList.add('alert-warn');
container.innerHTML = kagi_strings.loading_summary; container.innerHTML = loadingMsg;
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open('POST', url, true); request.open('POST', url, true);
@ -60,7 +62,7 @@ function summarizeButtonClick(button) {
badAjax(this.status == 403); badAjax(this.status == 403);
container.classList.remove('alert-warn'); container.classList.remove('alert-warn');
container.classList.add('alert-error'); container.classList.add('alert-error');
container.innerHTML = kagi_strings.error; container.innerHTML = errorMsg;
} }
request.setRequestHeader('Content-Type', 'application/json'); request.setRequestHeader('Content-Type', 'application/json');

View File

@ -1 +0,0 @@
var kagi_strings = <?= htmlspecialchars_decode(urldecode($this->kagi_strings)) ?>