2023-09-25 16:45:49 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController {
|
2023-09-25 19:02:54 -05:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2023-09-25 16:45:49 -05:00
|
|
|
public function summarizeAction() {
|
|
|
|
$this->view->_layout(false);
|
|
|
|
|
|
|
|
$kagi_token = FreshRSS_Context::$user_conf->kagi_token;
|
2023-09-28 11:02:25 -05:00
|
|
|
$kagi_language = FreshRSS_Context::$user_conf->kagi_language;
|
2023-09-25 16:45:49 -05:00
|
|
|
|
2023-09-25 19:02:54 -05:00
|
|
|
if ($kagi_token === null || trim($kagi_token) === '') {
|
2023-09-25 16:45:49 -05:00
|
|
|
echo json_encode(array(
|
|
|
|
'response' => array(
|
|
|
|
'output_text' => _t('ext.kagiSummarizer.ui.no_token_configured'),
|
|
|
|
'error' => 'configuration'),
|
|
|
|
'status' => 200));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry_id = Minz_Request::param('id');
|
|
|
|
$entry_dao = FreshRSS_Factory::createEntryDao();
|
|
|
|
$entry = $entry_dao->searchById($entry_id);
|
|
|
|
|
|
|
|
if ($entry === null) {
|
|
|
|
echo json_encode(array('status' => 404));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry_link = urlencode($entry->link());
|
2023-09-28 11:02:25 -05:00
|
|
|
$url = 'https://kagi.com/mother/summary_labs'
|
|
|
|
. '?summary_type=' . Minz_Request::param('type')
|
|
|
|
. '&target_language=' . $kagi_language
|
|
|
|
. '&url=' . $entry_link;
|
2023-09-25 16:45:49 -05:00
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
|
|
|
'Content-Type: application/json; charset=UTF-8',
|
|
|
|
'Authorization: ' . $kagi_token
|
|
|
|
));
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
|
|
|
|
echo json_encode(array(
|
2023-09-25 19:02:54 -05:00
|
|
|
'response' => json_decode($response),
|
2023-09-25 16:45:49 -05:00
|
|
|
'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|