2023-09-25 16:45:49 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class KagiSummarizerExtension extends Minz_Extension {
|
|
|
|
public function init() {
|
|
|
|
$this->registerTranslates();
|
|
|
|
$this->registerHook('entry_before_display', [$this, 'addSummarizeButton']);
|
|
|
|
Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, false, false);
|
2023-09-28 11:02:25 -05:00
|
|
|
Minz_View::appendStyle($this->getFileUrl('style.css', 'css'));
|
2023-09-25 19:02:54 -05:00
|
|
|
Minz_View::appendScript(_url('kagiSummarizer', 'kagiStrings'), false, true, false);
|
|
|
|
$this->registerViews();
|
2023-09-25 16:45:49 -05:00
|
|
|
$this->registerController('kagiSummarizer');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleConfigureAction() {
|
|
|
|
if (Minz_Request::isPost()) {
|
|
|
|
$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-28 11:02:25 -05:00
|
|
|
FreshRSS_Context::$user_conf->kagi_language = Minz_Request::param('kagi_language', '');
|
2024-09-25 14:24:23 -05:00
|
|
|
FreshRSS_Context::$user_conf->kagi_custom_css = Minz_Request::param('kagi_custom_css', '');
|
2023-09-25 16:45:49 -05:00
|
|
|
FreshRSS_Context::$user_conf->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addSummarizeButton(FreshRSS_Entry $entry): FreshRSS_Entry {
|
|
|
|
$this->registerTranslates();
|
2024-09-25 14:24:23 -05:00
|
|
|
$custom_css = FreshRSS_Context::$user_conf->kagi_custom_css;
|
2023-09-28 11:02:25 -05:00
|
|
|
$url_summary = Minz_Url::display(array(
|
2023-09-25 16:45:49 -05:00
|
|
|
'c' => 'kagiSummarizer',
|
|
|
|
'a' => 'summarize',
|
|
|
|
'params' => array(
|
2023-09-28 11:02:25 -05:00
|
|
|
'id' => $entry->id(),
|
|
|
|
'type' => 'summary',
|
|
|
|
)));
|
|
|
|
$url_key_moments = Minz_Url::display(array(
|
|
|
|
'c' => 'kagiSummarizer',
|
|
|
|
'a' => 'summarize',
|
|
|
|
'params' => array(
|
|
|
|
'id' => $entry->id(),
|
|
|
|
'type' => 'takeaway',
|
|
|
|
)));
|
2023-09-25 19:02:54 -05:00
|
|
|
$entry->_content(
|
2023-09-28 11:02:25 -05:00
|
|
|
'<div class="kagi-summary"><a class="btn" href="' . $url_summary .'">'
|
2023-09-28 11:08:56 -05:00
|
|
|
. _t('ext.kagiSummarizer.ui.summarize_button') . '</a>'
|
2023-09-28 11:02:25 -05:00
|
|
|
. '<a class="btn" href="' . $url_key_moments . '">'
|
|
|
|
. _t('ext.kagiSummarizer.ui.key_moments_button') . '</a>'
|
|
|
|
. '<p class="kagi-status hidden alert"></p>'
|
2024-09-25 14:24:23 -05:00
|
|
|
. '<blockquote class="kagi-content hidden" data-css="' . $custom_css . '"></blockquote></div>'
|
2023-09-25 19:02:54 -05:00
|
|
|
. $entry->content());
|
2023-09-25 16:45:49 -05:00
|
|
|
return $entry;
|
|
|
|
}
|
|
|
|
}
|