diff --git a/Controllers/kagiSummarizerController.php b/Controllers/kagiSummarizerController.php index eadc929..4a262f6 100644 --- a/Controllers/kagiSummarizerController.php +++ b/Controllers/kagiSummarizerController.php @@ -1,12 +1,22 @@ 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() { $this->view->_layout(false); $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( 'response' => array( 'output_text' => _t('ext.kagiSummarizer.ui.no_token_configured'), @@ -34,14 +44,10 @@ class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController { 'Authorization: ' . $kagi_token )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HEADER, true); - $response = curl_exec($curl); - $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - $response_body = substr($response, $header_size); echo json_encode(array( - 'response' => json_decode($response_body), + 'response' => json_decode($response), 'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE) )); } diff --git a/extension.php b/extension.php index adfd5da..3b340ca 100644 --- a/extension.php +++ b/extension.php @@ -5,6 +5,8 @@ class KagiSummarizerExtension extends Minz_Extension { $this->registerTranslates(); $this->registerHook('entry_before_display', [$this, 'addSummarizeButton']); 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'); } @@ -30,7 +32,10 @@ class KagiSummarizerExtension extends Minz_Extension { 'params' => array( 'id' => $entry->id() ))); - $entry->_content('
' . $entry->content()); + $entry->_content( + '' + . $entry->content()); return $entry; } } diff --git a/static/script.js b/static/script.js index cf75f0e..851b36f 100644 --- a/static/script.js +++ b/static/script.js @@ -21,13 +21,11 @@ function configureSummarizeButtons() { function summarizeButtonClick(button) { var url = button.href; - var loadingMsg = button.dataset.loading; - var errorMsg = button.dataset.error; var container = button.parentNode; container.classList.add('alert'); container.classList.add('alert-warn'); - container.innerHTML = loadingMsg; + container.innerHTML = kagi_strings.loading_summary; var request = new XMLHttpRequest(); request.open('POST', url, true); @@ -62,7 +60,7 @@ function summarizeButtonClick(button) { badAjax(this.status == 403); container.classList.remove('alert-warn'); container.classList.add('alert-error'); - container.innerHTML = errorMsg; + container.innerHTML = kagi_strings.error; } request.setRequestHeader('Content-Type', 'application/json'); diff --git a/views/kagiSummarizer/strings.js b/views/kagiSummarizer/strings.js new file mode 100644 index 0000000..96f83eb --- /dev/null +++ b/views/kagiSummarizer/strings.js @@ -0,0 +1 @@ +var kagi_strings = = htmlspecialchars_decode(urldecode($this->kagi_strings)) ?>