diff --git a/_admin.php b/_admin.php index fb967a7..4cd24f1 100644 --- a/_admin.php +++ b/_admin.php @@ -28,7 +28,7 @@ dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( ); # Admin behaviors -if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { +if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminKutrl', 'antispamDashboardFavoritesV2']); dcCore::app()->addBehavior('adminColumnsListsV2', ['adminKutrl', 'adminColumnsListsV2']); dcCore::app()->addBehavior('adminFiltersListsV2', ['adminKutrl', 'adminFiltersListsV2']); @@ -106,7 +106,7 @@ class adminKutrl { $s = dcCore::app()->blog->settings->get(basename(__DIR__)); - if (!$s->get('kutrl_active') || !$s->get('kutrl_admin_service')) { + if (!$s->get('active') || !$s->get('active')) { return null; } if (null === ($kut = kUtRL::quickPlace('admin'))) { @@ -125,7 +125,7 @@ class adminKutrl form::hidden(['kutrl_old_post_url'], $post_url); if (!$rs) { - if (empty($_POST['kutrl_old_post_url']) && $s->get('kutrl_admin_entry_default')) { + if (empty($_POST['kutrl_old_post_url']) && $s->get('admin_entry_default')) { $chk = true; } else { $chk = !empty($_POST['kutrl_create']); @@ -164,7 +164,7 @@ class adminKutrl public static function adminAfterPostUpdate($cur, $post_id) { # Create: see adminAfterPostCreate - if (!empty($_POST['kutrl_create']) || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { + if (!empty($_POST['kutrl_create']) || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } if (null === ($kut = kUtRL::quickPlace('admin'))) { @@ -210,7 +210,7 @@ class adminKutrl public static function adminAfterPostCreate($cur, $post_id) { - if (empty($_POST['kutrl_create']) || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { + if (empty($_POST['kutrl_create']) || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } @@ -238,7 +238,7 @@ class adminKutrl public static function adminBeforePostDelete($post_id) { - if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } @@ -256,7 +256,7 @@ class adminKutrl public static function adminPostsActions(dcPostsActions $pa) { - if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active') + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active') || !dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), dcCore::app()->blog->id)) { return null; } diff --git a/_config.php b/_config.php index b24771c..1b6072f 100644 --- a/_config.php +++ b/_config.php @@ -32,15 +32,15 @@ foreach (kUtRL::getServices() as $service_id => $service) { $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); $lst_services_combo = array_merge(['-' => ''], $services_combo); -$s_active = (bool) $s->get('kutrl_active'); -$s_plugin_service = (string) $s->get('kutrl_plugin_service'); -$s_admin_service = (string) $s->get('kutrl_admin_service'); -$s_tpl_service = (string) $s->get('kutrl_tpl_service'); -$s_wiki_service = (string) $s->get('kutrl_wiki_service'); -$s_allow_external_url = (bool) $s->get('kutrl_allow_external_url'); -$s_tpl_passive = (bool) $s->get('kutrl_tpl_passive'); -$s_tpl_active = (bool) $s->get('kutrl_tpl_active'); -$s_admin_entry_default = (string) $s->get('kutrl_admin_entry_default'); +$s_active = (bool) $s->get('active'); +$s_plugin_service = (string) $s->get('plugin_service'); +$s_admin_service = (string) $s->get('admin_service'); +$s_tpl_service = (string) $s->get('tpl_service'); +$s_wiki_service = (string) $s->get('wiki_service'); +$s_allow_external_url = (bool) $s->get('allow_external_url'); +$s_tpl_passive = (bool) $s->get('tpl_passive'); +$s_tpl_active = (bool) $s->get('tpl_active'); +$s_admin_entry_default = (string) $s->get('admin_entry_default'); if (!empty($_POST['save'])) { try { @@ -55,15 +55,15 @@ if (!empty($_POST['save'])) { $s_tpl_active = !empty($_POST['s_tpl_active']); $s_admin_entry_default = !empty($_POST['s_admin_entry_default']); - $s->put('kutrl_active', $s_active); - $s->put('kutrl_plugin_service', $s_plugin_service); - $s->put('kutrl_admin_service', $s_admin_service); - $s->put('kutrl_tpl_service', $s_tpl_service); - $s->put('kutrl_wiki_service', $s_wiki_service); - $s->put('kutrl_allow_external_url', $s_allow_external_url); - $s->put('kutrl_tpl_passive', $s_tpl_passive); - $s->put('kutrl_tpl_active', $s_tpl_active); - $s->put('kutrl_admin_entry_default', $s_admin_entry_default); + $s->put('active', $s_active); + $s->put('plugin_service', $s_plugin_service); + $s->put('admin_service', $s_admin_service); + $s->put('tpl_service', $s_tpl_service); + $s->put('wiki_service', $s_wiki_service); + $s->put('allow_external_url', $s_allow_external_url); + $s->put('tpl_passive', $s_tpl_passive); + $s->put('tpl_active', $s_tpl_active); + $s->put('admin_entry_default', $s_admin_entry_default); # services foreach (kUtRL::getServices() as $service_id => $service) { diff --git a/_install.php b/_install.php index e80ecf5..b2892e2 100644 --- a/_install.php +++ b/_install.php @@ -15,7 +15,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { } try { - # Compare versions + // Compare versions if (!dcCore::app()->newVersion( basename(__DIR__), dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') @@ -23,7 +23,7 @@ try { return null; } - # Table + // Table $t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $t->{initkUtRL::KURL_TABLE_NAME} ->kut_id('bigint', 0, false) @@ -45,35 +45,54 @@ try { $ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $changes = $ti->synchronize($t); - # Settings - $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); + // upgrade version < 2022.12.22 : upgrade settings id and ns and array + $current = dcCore::app()->getVersion(basename(__DIR__)); + if ($current && version_compare($current, '2022.12.22', '<')) { + $record = dcCore::app()->con->select( + 'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' . + "WHERE setting_ns = 'kUtRL' " + ); + while ($record->fetch()) { + if (preg_match('/^kutrl_(.*?)$/', $record->setting_id, $match)) { + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); + // avoid the use of serialize function + if (in_array($record->setting_id, ['kutrl_srv_custom'])) { + $cur->setting_value = json_encode(@unserialize(base64_decode((string) $record->setting_value))); + } + $cur->setting_id = $match[1]; + $cur->setting_ns = basename(__DIR__); + $cur->update( + "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'kUtRL' " . + 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' ")) + ); + } + } + } else { + // Settings + $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - $s->put('kutrl_active', false, 'boolean', 'Enabled kutrl plugin', false, true); - $s->put('kutrl_plugin_service', 'default', 'string', 'Service to use to shorten links on third part plugins', false, true); - $s->put('kutrl_admin_service', 'local', 'string', 'Service to use to shorten links on admin', false, true); - $s->put('kutrl_tpl_service', 'local', 'string', 'Service to use to shorten links on template', false, true); - $s->put('kutrl_wiki_service', 'local', 'string', 'Service to use to shorten links on contents', false, true); - $s->put('kutrl_allow_external_url', true, 'boolean', 'Limited short url to current blog\'s url', false, true); - $s->put('kutrl_tpl_passive', true, 'boolean', 'Return long url on kutrl tags if kutrl is unactivate', false, true); - $s->put('kutrl_tpl_active', false, 'boolean', 'Return short url on dotclear tags if kutrl is active', false, true); - $s->put('kutrl_admin_entry_default', true, 'boolean', 'Create short link on new entry by default', false, true); - # Settings for "local" service - $local_css = ".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" . - '.dc-kutrl input { border: 1px solid #CCCCCC; margin: 10px; }'; - $s->put('kutrl_srv_local_protocols', 'http:,https:,ftp:,ftps:,irc:', 'string', 'Allowed kutrl local service protocols', false, true); - $s->put('kutrl_srv_local_public', false, 'boolean', 'Enabled local service public page', false, true); - $s->put('kutrl_srv_local_css', $local_css, 'string', 'Special CSS for kutrl local service', false, true); - $s->put('kutrl_srv_local_404_active', false, 'boolean', 'Use special 404 page on unknow urls', false, true); - # Settings for "bilbolinks" service - $s->put('kutrl_srv_bilbolinks_base', 'http://tux-pla.net/', 'string', 'URL of bilbolinks service', false, true); - # Settings for "YOURLS" service - $s->put('kutrl_srv_yourls_base', '', 'string', 'URL of YOURLS service', false, true); - $s->put('kutrl_srv_yourls_username', '', 'string', 'User name to YOURLS service', false, true); - $s->put('kutrl_srv_yourls_password', '', 'string', 'User password to YOURLS service', false, true); - - # Get dcMiniUrl records as this plugin do the same - if (dcCore::app()->plugins->moduleExists('dcMiniUrl')) { - require_once __DIR__ . '/inc/patch.dcminiurl.php'; + $s->put('active', false, 'boolean', 'Enabled kutrl plugin', false, true); + $s->put('plugin_service', 'default', 'string', 'Service to use to shorten links on third part plugins', false, true); + $s->put('admin_service', 'local', 'string', 'Service to use to shorten links on admin', false, true); + $s->put('tpl_service', 'local', 'string', 'Service to use to shorten links on template', false, true); + $s->put('wiki_service', 'local', 'string', 'Service to use to shorten links on contents', false, true); + $s->put('allow_external_url', true, 'boolean', 'Limited short url to current blog\'s url', false, true); + $s->put('tpl_passive', true, 'boolean', 'Return long url on kutrl tags if kutrl is unactivate', false, true); + $s->put('tpl_active', false, 'boolean', 'Return short url on dotclear tags if kutrl is active', false, true); + $s->put('admin_entry_default', true, 'boolean', 'Create short link on new entry by default', false, true); + # Settings for "local" service + $local_css = ".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" . + '.dc-kutrl input { border: 1px solid #CCCCCC; margin: 10px; }'; + $s->put('srv_local_protocols', 'http:,https:,ftp:,ftps:,irc:', 'string', 'Allowed kutrl local service protocols', false, true); + $s->put('srv_local_public', false, 'boolean', 'Enabled local service public page', false, true); + $s->put('srv_local_css', $local_css, 'string', 'Special CSS for kutrl local service', false, true); + $s->put('srv_local_404_active', false, 'boolean', 'Use special 404 page on unknow urls', false, true); + # Settings for "bilbolinks" service + $s->put('srv_bilbolinks_base', 'http://tux-pla.net/', 'string', 'URL of bilbolinks service', false, true); + # Settings for "YOURLS" service + $s->put('srv_yourls_base', '', 'string', 'URL of YOURLS service', false, true); + $s->put('srv_yourls_username', '', 'string', 'User name to YOURLS service', false, true); + $s->put('srv_yourls_password', '', 'string', 'User password to YOURLS service', false, true); } return true; diff --git a/_public.php b/_public.php index 0b412e7..8748e86 100644 --- a/_public.php +++ b/_public.php @@ -51,7 +51,7 @@ class urlKutrl extends dcUrlHandlers public static function redirectUrl($args) { # Not active, go to default 404 - if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { self::p404(); return null; @@ -112,13 +112,13 @@ class urlKutrl extends dcUrlHandlers $s = dcCore::app()->blog->settings->get(basename(__DIR__)); # Not active, go to default 404 - if (!$s->get('kutrl_active')) { + if (!$s->get('active')) { self::p404(); return null; } # Public page not active, go to kutrl 404 - if (!$s->get('kutrl_srv_local_public')) { + if (!$s->get('srv_local_public')) { self::kutrl404(); return null; @@ -218,7 +218,7 @@ class urlKutrl extends dcUrlHandlers protected static function kutrl404() { - if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_srv_local_404_active')) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('srv_local_404_active')) { self::p404(); return null; @@ -284,8 +284,8 @@ class pubKutrl # URL shortening is disabled by tag attribute if (true !== dcCore::app()->ctx->__get('disable_kutrl')) { # kUtRL is not activated - if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active') - || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_tpl_active') + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active') + || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('tpl_active') ) { return null; } @@ -314,9 +314,9 @@ class pubKutrl $s = dcCore::app()->blog->settings->get(basename(__DIR__)); # Passive : all kutrl tag return long url - dcCore::app()->ctx->kutrl_passive = (bool) $s->get('kutrl_tpl_passive'); + dcCore::app()->ctx->kutrl_passive = (bool) $s->get('tpl_passive'); - if (!$s->get('kutrl_active') || !$s->get('kutrl_tpl_service')) { + if (!$s->get('active') || !$s->get('tpl_service')) { return null; } if (null === ($kut = kUtRL::quickPlace('tpl'))) { @@ -327,7 +327,7 @@ class pubKutrl public static function publicHeadContent($_) { - $css = dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_srv_local_css'); + $css = dcCore::app()->blog->settings->get(basename(__DIR__))->get('srv_local_css'); if ($css) { echo "\n \n" . @@ -353,7 +353,7 @@ class tplKutrl if (isset($attr['is_active'])) { $sign = (bool) $attr['is_active'] ? '' : '!'; - $if[] = $sign . 'dcCore::app()->blog->settings->get("kUtRL")->get("kutrl_srv_local_public")'; + $if[] = $sign . 'dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("srv_local_public")'; } if (empty($if)) { return $content; diff --git a/_uninstall.php b/_uninstall.php index 097d17c..fccd2ab 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -69,7 +69,7 @@ $this->addDirectAction( /* ns */ basename(__DIR__), /* description */ - sprintf(__('delete all %s settings'), 'kUtRL') + sprintf(__('delete all %s settings'), basename(__DIR__)) ); $this->addDirectAction( @@ -80,7 +80,7 @@ $this->addDirectAction( /* ns */ basename(__DIR__), /* description */ - sprintf(__('delete %s version number'), 'kUtRL') + sprintf(__('delete %s version number'), basename(__DIR__)) ); $this->addDirectAction( @@ -91,5 +91,5 @@ $this->addDirectAction( /* ns */ basename(__DIR__), /* description */ - sprintf(__('delete %s plugin files'), 'kUtRL') + sprintf(__('delete %s plugin files'), basename(__DIR__)) ); diff --git a/_widgets.php b/_widgets.php index bbb684c..353ed95 100644 --- a/_widgets.php +++ b/_widgets.php @@ -116,8 +116,8 @@ class widgetKutrl { $s = dcCore::app()->blog->settings->get(basename(__DIR__)); - if (!$s->get('kutrl_active') - || !$s->get('kutrl_srv_local_public') + if (!$s->get('active') + || !$s->get('srv_local_public') || !$w->checkHomeOnly(dcCore::app()->url->type) || dcCore::app()->url->type == 'kutrl') { return null; @@ -153,7 +153,7 @@ class widgetKutrl { $s = dcCore::app()->blog->settings->get(basename(__DIR__)); - if (!$s->get('kutrl_active') || !$w->checkHomeOnly(dcCore::app()->url->type)) { + if (!$s->get('active') || !$w->checkHomeOnly(dcCore::app()->url->type)) { return null; } diff --git a/inc/class.kutrl.php b/inc/class.kutrl.php index 7bdd60e..c315429 100644 --- a/inc/class.kutrl.php +++ b/inc/class.kutrl.php @@ -63,7 +63,7 @@ class kUtRL if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) { return null; } - $id = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('kutrl_' . $place . '_service'); + $id = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get($place . '_service'); if (!empty($id)) { return self::quickService($id); } diff --git a/inc/lib.kutrl.srv.php b/inc/lib.kutrl.srv.php index c627cfe..7fdcd35 100644 --- a/inc/lib.kutrl.srv.php +++ b/inc/lib.kutrl.srv.php @@ -30,7 +30,7 @@ class kutrlService $this->init(); // Force setting - $allow_external_url = $this->settings->get('kutrl_allow_external_url'); + $allow_external_url = $this->settings->get('allow_external_url'); $this->config['$allow_external_url'] = null === $allow_external_url ? true : $allow_external_url; @@ -44,7 +44,7 @@ class kutrlService 'allow_custom_hash' => false, 'allow_protocols' => ['http://'], - 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', + 'url_test' => 'http://github.com/JcDenis/kUtRL/releases', 'url_api' => '', 'url_base' => '', 'url_min_len' => 0, @@ -218,7 +218,7 @@ class kutrlService { $url = (string) $server; $client = netHttp::initClient($url, $url); - $client->setUserAgent('kUtRL - http://kutrl.fr'); + $client->setUserAgent('kUtRL - https://github.com/JcDenis/kUtRL'); $client->setPersistReferers(false); if (is_array($headers) && !empty($headers)) { diff --git a/inc/lib.wiki.kutrl.php b/inc/lib.wiki.kutrl.php index 710271f..0d42259 100644 --- a/inc/lib.wiki.kutrl.php +++ b/inc/lib.wiki.kutrl.php @@ -23,7 +23,7 @@ class kutrlWiki # Do nothing on comment preview and post preview if (!empty($_POST['preview']) || isset(dcCore::app()->ctx) && dcCore::app()->ctx->preview - || !dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('kutrl_active') + || !dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('active') ) { return null; } @@ -40,7 +40,7 @@ class kutrlWiki public static function transform($url, $content) { - if (!dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('kutrl_active')) { + if (!dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('active')) { return null; } if (null === ($kut = kUtRL::quickPlace('wiki'))) { diff --git a/inc/patch.dcminiurl.php b/inc/patch.dcminiurl.php deleted file mode 100644 index 9d205ce..0000000 --- a/inc/patch.dcminiurl.php +++ /dev/null @@ -1,130 +0,0 @@ -parseRecords()) { - try { - dcCore::app()->plugins->deactivateModule('dcMiniUrl'); - } catch (Exception $e) { - //dcCore::app()->error->add($e->getMessage()); - } -} - -class dcMiniUrl2kUtRL -{ - public $con; - public $k_tb; - public $m_tb; - - public function __construct() - { - $this->con = dcCore::app()->con; - $this->k_tb = dcCore::app()->prefix . initkUtRL::KURL_TABLE_NAME; - $this->m_tb = dcCore::app()->prefix . 'miniurl'; - } - - public function parseRecords() - { - $rs = $this->con->select( - 'SELECT * FROM ' . $this->m_tb . ' ' - ); - - while ($rs->fetch()) { - if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') { - if ($this->exists($rs)) { - continue; - } - - $this->insertKutrl($rs); - $this->insertLocal($rs); - } else { - $this->insertOther($rs); - } - } - - return true; - } - - private function insertKutrl($rs) - { - $cur = $this->common($rs); - $cur->kut_service = 'kutrl'; - $cur->kut_type = 'local'; - $cur->kut_counter = 0; - $cur->kut_password = null; - - $cur->insert(); - $this->con->unlock(); - } - - private function insertLocal($rs) - { - $cur = $this->common($rs); - $cur->kut_service = 'local'; - $cur->kut_type = $rs->miniurl_type == 'customurl' ? - 'localcustom' : 'localnormal'; - - $cur->insert(); - $this->con->unlock(); - } - - private function insertOther($rs) - { - $cur = $this->common($rs); - - $cur->insert(); - $this->con->unlock(); - } - - private function common($rs) - { - $cur = $this->con->openCursor($this->k_tb); - $this->con->writeLock($this->k_tb); - $cur->kut_id = $this->nextId(); - $cur->blog_id = $rs->blog_id; - $cur->kut_service = 'unknow'; - $cur->kut_type = $rs->miniurl_type; - $cur->kut_hash = $rs->miniurl_id; - $cur->kut_url = $rs->miniurl_str; - $cur->kut_dt = $rs->miniurl_dt; - $cur->kut_counter = $rs->miniurl_counter; - $cur->kut_password = $rs->miniurl_password; - - return $cur; - } - - private function exists($rs) - { - $chk = $this->con->select( - 'SELECT kut_hash FROM ' . $this->k_tb . ' ' . - "WHERE blog_id = '" . $rs->blog_id . "' " . - "AND kut_service = 'local' " . - "AND kut_hash = '" . $rs->miniurl_id . "' " - ); - - return !$chk->isEmpty(); - } - - private function nextId() - { - return $this->con->select( - 'SELECT MAX(kut_id) FROM ' . $this->k_tb . ' ' - )->f(0) + 1; - } -} diff --git a/inc/services/class.bilbolinks.service.php b/inc/services/class.bilbolinks.service.php index 09dd97a..572f413 100644 --- a/inc/services/class.bilbolinks.service.php +++ b/inc/services/class.bilbolinks.service.php @@ -24,7 +24,7 @@ class bilbolinksKutrlService extends kutrlService protected function init() { - $base = (string) $this->settings->get('kutrl_srv_bilbolinks_base'); + $base = (string) $this->settings->get('srv_bilbolinks_base'); if (!empty($base) && substr($base, -1, 1) != '/') { $base .= '/'; } @@ -42,7 +42,7 @@ class bilbolinksKutrlService extends kutrlService $base .= '/'; } } - $this->settings->put('kutrl_srv_bilbolinks_base', $base); + $this->settings->put('srv_bilbolinks_base', $base); } public function settingsForm() @@ -50,7 +50,7 @@ class bilbolinksKutrlService extends kutrlService echo '
' . '' . __('This is the root URL of the "bilbolinks" service you want to use. Ex: "http://tux-pla.net/".') . diff --git a/inc/services/class.bitly.service.php b/inc/services/class.bitly.service.php index d3190a7..a08b83a 100644 --- a/inc/services/class.bitly.service.php +++ b/inc/services/class.bitly.service.php @@ -34,19 +34,19 @@ class bitlyKutrlService extends kutrlService protected function init() { - $this->args['apiKey'] = $this->settings->kutrl_srv_bitly_apikey; + $this->args['apiKey'] = $this->settings->get('srv_bitly_apikey'); } public function saveSettings() { - $this->settings->put('kutrl_srv_bitly_apikey', $_POST['kutrl_srv_bitly_apikey']); + $this->settings->put('srv_bitly_apikey', $_POST['kutrl_srv_bitly_apikey']); } public function settingsForm() { echo '
' . '' . sprintf(__('This is your personnal %s API key. You can find it on your account page.'), $this->config['name']) . diff --git a/inc/services/class.custom.service.php b/inc/services/class.custom.service.php index 9a21be5..6df5b3f 100644 --- a/inc/services/class.custom.service.php +++ b/inc/services/class.custom.service.php @@ -23,14 +23,14 @@ class customKutrlService extends kutrlService protected function init() { - $config = unserialize(base64_decode((string) $this->settings->get('kutrl_srv_custom'))); + $config = json_decode((string) $this->settings->get('srv_custom'), true); if (!is_array($config)) { $config = []; } - $this->config['url_api'] = !empty($config['url_api']) ? $config['url_api'] : ''; - $this->config['url_base'] = !empty($config['url_base']) ? $config['url_base'] : ''; - $this->config['url_param'] = !empty($config['url_param']) ? $config['url_param'] : ''; + $this->config['url_api'] = $config['url_api'] ?? ''; + $this->config['url_base'] = $config['url_base'] ?? ''; + $this->config['url_param'] = $config['url_param'] ?? ''; $this->config['url_encode'] = !empty($config['url_api']); $this->config['url_min_length'] = strlen($this->url_base) + 2; @@ -44,7 +44,7 @@ class customKutrlService extends kutrlService 'url_param' => $_POST['kutrl_srv_custom_url_param'], 'url_encode' => !empty($_POST['kutrl_srv_custom_url_encode']), ]; - $this->settings->put('kutrl_srv_custom', base64_encode(serialize($config))); + $this->settings->put('srv_custom', json_encode($config)); } public function settingsForm() @@ -55,7 +55,7 @@ class customKutrlService extends kutrlService 'url_param' => '', 'url_encode' => true, ]; - $config = unserialize(base64_decode((string) $this->settings->get('kutrl_srv_custom'))); + $config = json_decode((string) $this->settings->get('srv_custom'), true); if (!is_array($config)) { $config = []; } diff --git a/inc/services/class.googl.service.php b/inc/services/class.googl.service.php index eb34db5..ba787d7 100644 --- a/inc/services/class.googl.service.php +++ b/inc/services/class.googl.service.php @@ -21,7 +21,7 @@ class googlKutrlService extends kutrlService public $home = 'http://goo.gl'; private $url_api = 'https://www.googleapis.com/urlshortener/v1/url'; - private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; + private $url_test = 'https://github.com/JcDenis/kUtRL/releases'; private $args = [ 'key' => '', ]; diff --git a/inc/services/class.local.service.php b/inc/services/class.local.service.php index 588e2ef..80bd24d 100644 --- a/inc/services/class.local.service.php +++ b/inc/services/class.local.service.php @@ -26,7 +26,7 @@ class localKutrlService extends kutrlService protected function init() { - $protocols = (string) $this->settings->get('kutrl_srv_local_protocols'); + $protocols = (string) $this->settings->get('srv_local_protocols'); $this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols); $this->config['url_base'] = dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/'; @@ -35,10 +35,10 @@ class localKutrlService extends kutrlService public function saveSettings() { - $this->settings->put('kutrl_srv_local_protocols', $_POST['kutrl_srv_local_protocols'], 'string'); - $this->settings->put('kutrl_srv_local_public', isset($_POST['kutrl_srv_local_public']), 'boolean'); - $this->settings->put('kutrl_srv_local_css', $_POST['kutrl_srv_local_css'], 'string'); - $this->settings->put('kutrl_srv_local_404_active', isset($_POST['kutrl_srv_local_404_active']), 'boolean'); + $this->settings->put('srv_local_protocols', $_POST['kutrl_srv_local_protocols'], 'string'); + $this->settings->put('srv_local_public', isset($_POST['kutrl_srv_local_public']), 'boolean'); + $this->settings->put('srv_local_css', $_POST['kutrl_srv_local_css'], 'string'); + $this->settings->put('srv_local_404_active', isset($_POST['kutrl_srv_local_404_active']), 'boolean'); } public function settingsForm() @@ -49,7 +49,7 @@ class localKutrlService extends kutrlService '
' . __('Settings:') . '
' . '' . '' . @@ -57,17 +57,17 @@ class localKutrlService extends kutrlService '
' . '' . '' . - form::textarea('kutrl_srv_local_css', 50, 3, html::escapeHTML($this->settings->get('kutrl_srv_local_css')), '', '2') . + form::textarea('kutrl_srv_local_css', 50, 3, html::escapeHTML($this->settings->get('srv_local_css')), '', '2') . '
' . '' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '
' . '' . '' . __('If this is not activated, the default 404 page of the theme will be display.') . '
' . diff --git a/inc/services/class.supr.service.php b/inc/services/class.supr.service.php index 81c14ce..c0f000d 100644 --- a/inc/services/class.supr.service.php +++ b/inc/services/class.supr.service.php @@ -35,27 +35,27 @@ class suprKutrlService extends kutrlService protected function init() { - $this->args['login'] = $this->settings->get('kutrl_srv_supr_login'); - $this->args['apiKey'] = $this->settings->get('kutrl_srv_supr_apikey'); + $this->args['login'] = $this->settings->get('srv_supr_login'); + $this->args['apiKey'] = $this->settings->get('srv_supr_apikey'); } public function saveSettings() { - $this->settings->put('kutrl_srv_supr_login', $_POST['kutrl_srv_supr_login']); - $this->settings->put('kutrl_srv_supr_apikey', $_POST['kutrl_srv_supr_apikey']); + $this->settings->put('srv_supr_login', $_POST['kutrl_srv_supr_login']); + $this->settings->put('srv_supr_apikey', $_POST['kutrl_srv_supr_apikey']); } public function settingsForm() { echo '' . '' . sprintf(__('This is your login to sign up to %s'), $this->config['name']) . '
' . '' . '' . sprintf(__('This is your personnal %s API key. You can find it on your account page.'), $this->config['name']) . diff --git a/inc/services/class.trim.service.php b/inc/services/class.trim.service.php index 6a1d36a..325166d 100644 --- a/inc/services/class.trim.service.php +++ b/inc/services/class.trim.service.php @@ -35,29 +35,29 @@ class trimKutrlService extends kutrlService protected function init() { - $this->args['username'] = $this->settings->get('kutrl_srv_trim_username'); - $this->args['password'] = $this->settings->get('kutrl_srv_trim_password'); + $this->args['username'] = $this->settings->get('srv_trim_username'); + $this->args['password'] = $this->settings->get('srv_trim_password'); - $this->api_rate_time = (int) $this->settings->get('kutrl_srv_trim_apiratetime'); + $this->api_rate_time = (int) $this->settings->get('srv_trim_apiratetime'); } public function saveSettings() { - $this->settings->put('kutrl_srv_trim_username', $_POST['kutrl_srv_trim_username']); - $this->settings->put('kutrl_srv_trim_password', $_POST['kutrl_srv_trim_password']); + $this->settings->put('srv_trim_username', $_POST['kutrl_srv_trim_username']); + $this->settings->put('srv_trim_password', $_POST['kutrl_srv_trim_password']); } public function settingsForm() { echo '
' . '' . __('This is your login to sign up to tr.im.') . '
' . '' . '' . __('This is your password to sign up to tr.im.') . @@ -106,7 +106,7 @@ class trimKutrlService extends kutrlService # API rate limit if ($r['code'] == 425) { - $this->settings->put('kutrl_srv_trim_apiratetime', time()); + $this->settings->put('srv_trim_apiratetime', time()); $this->error->add(__('Service rate limit exceeded.')); diff --git a/inc/services/class.yourls.service.php b/inc/services/class.yourls.service.php index 69befe9..d354557 100644 --- a/inc/services/class.yourls.service.php +++ b/inc/services/class.yourls.service.php @@ -31,10 +31,10 @@ class yourlsKutrlService extends kutrlService protected function init() { - $this->args['username'] = $this->settings->get('kutrl_srv_yourls_username'); - $this->args['password'] = $this->settings->get('kutrl_srv_yourls_password'); + $this->args['username'] = $this->settings->get('srv_yourls_username'); + $this->args['password'] = $this->settings->get('srv_yourls_password'); - $base = (string) $this->settings->get('kutrl_srv_yourls_base'); + $base = (string) $this->settings->get('srv_yourls_base'); //if (!empty($base) && substr($base,-1,1) != '/') $base .= '/'; $this->config['url_api'] = $base; @@ -44,9 +44,9 @@ class yourlsKutrlService extends kutrlService public function saveSettings() { - $this->settings->put('kutrl_srv_yourls_username', $_POST['kutrl_srv_yourls_username']); - $this->settings->put('kutrl_srv_yourls_password', $_POST['kutrl_srv_yourls_password']); - $this->settings->put('kutrl_srv_yourls_base', $_POST['kutrl_srv_yourls_base']); + $this->settings->put('srv_yourls_username', $_POST['kutrl_srv_yourls_username']); + $this->settings->put('srv_yourls_password', $_POST['kutrl_srv_yourls_password']); + $this->settings->put('srv_yourls_base', $_POST['kutrl_srv_yourls_base']); } public function settingsForm() @@ -54,19 +54,19 @@ class yourlsKutrlService extends kutrlService echo '
' . '' . __('This is the URL of the YOURLS service you want to use. Ex: "http://www.smaller.org/api.php".') . '
' . '' . '' . __('This is your user name to sign up to this YOURLS service.') . '
' . '' . '' . __('This is your password to sign up to this YOURLS service.') . diff --git a/index.php b/index.php index d971de9..a8391c4 100644 --- a/index.php +++ b/index.php @@ -131,8 +131,8 @@ if ($part == 'link') { dcCore::app()->error->add($e->getMessage()); } - $header = $kUtRL_filter->js(dcCore::app()->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) . - dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); + $header = $kUtRL_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__), ['part' => 'links'])) . + dcPage::jsModuleLoad(basename(__DIR__) . '/js/admin.js'); if (!empty($_POST['deletelinks'])) { try { @@ -152,7 +152,7 @@ if ($part == 'link') { dcAdminNotices::addSuccessNotice( __('Links successfully deleted') ); - dcCore::app()->adminurl->redirect('admin.plugin.kUtRL', $kUtRL_filter->values()); + dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__), $kUtRL_filter->values()); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -170,7 +170,7 @@ if ($part == 'link') { echo dcPage::breadcrumb([ __('Plugins') => '', - __('Links shortener') => dcCore::app()->adminurl->get('admin.plugin.kUtRL'), + __('Links shortener') => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), __('New link') => '', ]) . dcPage::notices(); @@ -181,7 +181,7 @@ if ($part == 'link') { echo '
' . - dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . + dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . basename(__DIR__), array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . dcCore::app()->formNonce() . '