2023-09-25 11:49:34 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class KagiSummarizerExtension extends Minz_Extension {
|
|
|
|
public function init() {
|
|
|
|
$this->registerTranslates();
|
2023-09-25 13:08:57 -05:00
|
|
|
$this->registerHook('entry_before_display', [$this, 'addSummarizeButton']);
|
2023-09-25 13:30:27 -05:00
|
|
|
Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, false, false);
|
2023-09-25 15:28:13 -05:00
|
|
|
$this->registerController('kagiSummarizer');
|
2023-09-25 11:49:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function handleConfigureAction() {
|
|
|
|
$this->registerTranslates();
|
|
|
|
|
|
|
|
if (Minz_Request::isPost()) {
|
2023-09-25 12:38:33 -05:00
|
|
|
$kagi_token = Minz_Request::param('kagi_token', '');
|
|
|
|
$prefix = 'https://kagi.com/search?token=';
|
|
|
|
if (substr($kagi_token, 0, strlen($prefix)) == $prefix) {
|
|
|
|
$kagi_token = substr($kagi_token, strlen($prefix));
|
|
|
|
}
|
|
|
|
FreshRSS_Context::$user_conf->kagi_token = $kagi_token;
|
2023-09-25 11:49:34 -05:00
|
|
|
FreshRSS_Context::$user_conf->save();
|
|
|
|
}
|
2023-09-25 11:52:51 -05:00
|
|
|
}
|
2023-09-25 13:05:04 -05:00
|
|
|
|
|
|
|
public function addSummarizeButton(FreshRSS_Entry $entry): FreshRSS_Entry {
|
2023-09-25 13:24:33 -05:00
|
|
|
$this->registerTranslates();
|
2023-09-25 15:28:13 -05:00
|
|
|
$url = Minz_Url::display(array(
|
|
|
|
'c' => 'kagiSummarizer',
|
|
|
|
'a' => 'summarize',
|
|
|
|
'params' => array(
|
|
|
|
'id' => $entry->id()
|
|
|
|
)));
|
2023-09-25 15:57:46 -05:00
|
|
|
$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());
|
2023-09-25 13:05:04 -05:00
|
|
|
return $entry;
|
|
|
|
}
|
2023-09-25 11:49:34 -05:00
|
|
|
}
|