diff --git a/_admin.php b/_admin.php index c993bcd..fb967a7 100644 --- a/_admin.php +++ b/_admin.php @@ -14,24 +14,24 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -dcCore::app()->blog->settings->addNamespace('kUtRL'); +dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); require_once __DIR__ . '/_widgets.php'; # Plugin menu dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Links shortener'), - dcCore::app()->adminurl->get('admin.plugin.kUtRL'), - urldecode(dcPage::getPF('kUtRL/icon.svg')), - preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), + urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')), + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), dcCore::app()->blog->id) ); # Admin behaviors -if (dcCore::app()->blog->settings->kUtRL->kutrl_active) { - dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminKutrl', 'antispamDashboardFavorites']); - dcCore::app()->addBehavior('adminColumnsListsV2', ['adminKutrl', 'adminColumnsLists']); - dcCore::app()->addBehavior('adminFiltersListsV2', ['adminKutrl', 'adminFiltersLists']); +if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { + dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminKutrl', 'antispamDashboardFavoritesV2']); + dcCore::app()->addBehavior('adminColumnsListsV2', ['adminKutrl', 'adminColumnsListsV2']); + dcCore::app()->addBehavior('adminFiltersListsV2', ['adminKutrl', 'adminFiltersListsV2']); dcCore::app()->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); dcCore::app()->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']); dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url @@ -41,11 +41,11 @@ if (dcCore::app()->blog->settings->kUtRL->kutrl_active) { dcCore::app()->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']); } -dcCore::app()->addBehavior('exportFullV2', ['backupKutrl', 'exportFull']); -dcCore::app()->addBehavior('exportSingleV2', ['backupKutrl', 'exportSingle']); -dcCore::app()->addBehavior('importInitV2', ['backupKutrl', 'importInit']); -dcCore::app()->addBehavior('importSingleV2', ['backupKutrl', 'importSingle']); -dcCore::app()->addBehavior('importFullV2', ['backupKutrl', 'importFull']); +dcCore::app()->addBehavior('exportFullV2', ['backupKutrl', 'exportFullV2']); +dcCore::app()->addBehavior('exportSingleV2', ['backupKutrl', 'exportSingleV2']); +dcCore::app()->addBehavior('importInitV2', ['backupKutrl', 'importInitV2']); +dcCore::app()->addBehavior('importSingleV2', ['backupKutrl', 'importSingleV2']); +dcCore::app()->addBehavior('importFullV2', ['backupKutrl', 'importFullV2']); # Admin behaviors class class adminKutrl @@ -60,21 +60,21 @@ class adminKutrl ]; } - public static function antispamDashboardFavorites(dcFavorites $favs) + public static function antispamDashboardFavoritesV2(dcFavorites $favs) { $favs->register( 'kUtRL', [ 'title' => __('Links shortener'), - 'url' => dcCore::app()->adminurl->get('admin.plugin.kUtRL'), - 'small-icon' => dcPage::getPF('kUtRL/icon.png'), - 'large-icon' => dcPage::getPF('kUtRL/icon-b.png'), + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), + 'small-icon' => dcPage::getPF(basename(__DIR__) . '/icon.png'), + 'large-icon' => dcPage::getPF(basename(__DIR__) . '/icon-b.png'), 'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), ] ); } - public static function adminColumnsLists($cols) + public static function adminColumnsListsV2($cols) { $cols['kUtRL'] = [ __('Links shortener'), @@ -86,7 +86,7 @@ class adminKutrl ]; } - public static function adminFiltersLists($sorts) + public static function adminFiltersListsV2($sorts) { $sorts['kUtRL'] = [ __('Links shortener'), @@ -99,14 +99,14 @@ class adminKutrl public static function adminPostHeaders() { - return dcPage::jsLoad(dcPage::getPF('kUtRL/js/posts.js')); + return dcPage::jsModuleLoad(basename(__DIR__) . '/js/posts.js'); } public static function adminPostFormItems($main_items, $sidebar_items, $post) { - $s = dcCore::app()->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); - if (!$s->kutrl_active || !$s->kutrl_admin_service) { + if (!$s->get('kutrl_active') || !$s->get('kutrl_admin_service')) { return null; } if (null === ($kut = kUtRL::quickPlace('admin'))) { @@ -125,19 +125,19 @@ class adminKutrl form::hidden(['kutrl_old_post_url'], $post_url); if (!$rs) { - if (empty($_POST['kutrl_old_post_url']) && $s->kutrl_admin_entry_default) { + if (empty($_POST['kutrl_old_post_url']) && $s->get('kutrl_admin_entry_default')) { $chk = true; } else { $chk = !empty($_POST['kutrl_create']); } $ret .= '

'; if ($kut->allow_custom_hash) { $ret .= '

' . '

'; } } else { @@ -152,7 +152,7 @@ class adminKutrl $href = $kut->url_base . $rs->hash; $ret .= '

' . '

' . $href . '

'; } @@ -163,10 +163,8 @@ class adminKutrl public static function adminAfterPostUpdate($cur, $post_id) { - $s = dcCore::app()->blog->settings->kUtRL; - # Create: see adminAfterPostCreate - if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) { + if (!empty($_POST['kutrl_create']) || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { return null; } if (null === ($kut = kUtRL::quickPlace('admin'))) { @@ -200,7 +198,7 @@ class adminKutrl $kut->remove($old_post_url); - $rs = $kut->hash($new_post_url, $custom); // better to update (not yet implemented) + $rs = $kut->hash($new_post_url, '');//$custom); // better to update (not yet implemented) $url = $kut->url_base . $rs->hash; # ex: Send new url to messengers @@ -212,11 +210,10 @@ class adminKutrl public static function adminAfterPostCreate($cur, $post_id) { - $s = dcCore::app()->blog->settings->kUtRL; - - if (empty($_POST['kutrl_create']) || !$s->kutrl_active) { + if (empty($_POST['kutrl_create']) || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { return null; } + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } @@ -241,11 +238,10 @@ class adminKutrl public static function adminBeforePostDelete($post_id) { - $s = dcCore::app()->blog->settings->kUtRL; - - if (!$s->kutrl_active) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { return null; } + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } @@ -260,9 +256,7 @@ class adminKutrl public static function adminPostsActions(dcPostsActions $pa) { - $s = dcCore::app()->blog->settings->kUtRL; - - if (!$s->kutrl_active + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active') || !dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), dcCore::app()->blog->id)) { return null; } @@ -279,10 +273,6 @@ class adminKutrl public static function callbackCreate(dcPostsActions $pa, ArrayObject $post) { - if (null === ($kut = kUtRL::quickPlace('admin'))) { - return null; - } - # No entry $posts_ids = $pa->getIDs(); if (empty($posts_ids)) { @@ -294,6 +284,10 @@ class adminKutrl throw new Exception(__('No enough right')); } + if (null === ($kut = kUtRL::quickPlace('admin'))) { + return null; + } + # retrieve posts info and create hash $posts = dcCore::app()->blog->getPosts(['post_id' => $posts_ids]); while ($posts->fetch()) { @@ -317,6 +311,10 @@ class adminKutrl throw new Exception(__('No enough right')); } + if (null === ($kut = kUtRL::quickPlace('admin'))) { + return null; + } + # retrieve posts info and create hash $posts = dcCore::app()->blog->getPosts(['post_id' => $posts_ids]); while ($posts->fetch()) { @@ -331,7 +329,7 @@ class adminKutrl # Import/export behaviors for Import/export plugin class backupKutrl { - public static function exportSingle($exp, $blog_id) + public static function exportSingleV2($exp, $blog_id) { $exp->export( 'kutrl', @@ -342,18 +340,18 @@ class backupKutrl ); } - public static function exportFull($exp) + public static function exportFullV2($exp) { $exp->exportTable('kutrl'); } - public static function importInit($bk) + public static function importInitV2($bk) { $bk->cur_kutrl = dcCore::app()->con->openCursor(dcCore::app()->prefix . initkUtRL::KURL_TABLE_NAME); $bk->kutrl = new kutrlLog(); } - public static function importSingle($line, $bk) + public static function importSingleV2($line, $bk) { if ($line->__name == 'kutrl') { # Do nothing if str/type exists ! @@ -363,7 +361,7 @@ class backupKutrl } } - public static function importFull($line, $bk) + public static function importFullV2($line, $bk) { if ($line->__name == 'kutrl') { $bk->cur_kutrl->clean(); diff --git a/_config.php b/_config.php index 38d2d1d..b24771c 100644 --- a/_config.php +++ b/_config.php @@ -18,7 +18,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN])); # Settings -$s = dcCore::app()->blog->settings->kUtRL; +$s = dcCore::app()->blog->settings->get(basename(__DIR__)); # Default values $img_green = 'ok'; @@ -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->kutrl_active; -$s_plugin_service = (string) $s->kutrl_plugin_service; -$s_admin_service = (string) $s->kutrl_admin_service; -$s_tpl_service = (string) $s->kutrl_tpl_service; -$s_wiki_service = (string) $s->kutrl_wiki_service; -$s_allow_external_url = (bool) $s->kutrl_allow_external_url; -$s_tpl_passive = (bool) $s->kutrl_tpl_passive; -$s_tpl_active = (bool) $s->kutrl_tpl_active; -$s_admin_entry_default = (string) $s->kutrl_admin_entry_default; +$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'); if (!empty($_POST['save'])) { try { @@ -79,7 +79,7 @@ if (!empty($_POST['save'])) { dcCore::app()->adminurl->redirect( 'admin.plugins', - ['module' => 'kUtRL', 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] + ['module' => basename(__DIR__), 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] ); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); diff --git a/_install.php b/_install.php index 8c2f505..e80ecf5 100644 --- a/_install.php +++ b/_install.php @@ -17,7 +17,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { try { # Compare versions if (!dcCore::app()->newVersion( - basename(__DIR__), + basename(__DIR__), dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') )) { return null; @@ -46,8 +46,8 @@ try { $changes = $ti->synchronize($t); # Settings - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - $s = dcCore::app()->blog->settings->__get(basename(__DIR__)); + $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); diff --git a/_public.php b/_public.php index 63a40ca..0b412e7 100644 --- a/_public.php +++ b/_public.php @@ -18,11 +18,11 @@ require_once __DIR__ . '/_widgets.php'; dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates'); -dcCore::app()->addBehavior('publicBeforeDocumentV2', ['pubKutrl', 'publicBeforeDocument']); +dcCore::app()->addBehavior('publicBeforeDocumentV2', ['pubKutrl', 'publicBeforeDocumentV2']); dcCore::app()->addBehavior('publicHeadContent', ['pubKutrl', 'publicHeadContent']); -dcCore::app()->addBehavior('publicBeforeContentFilterV2', ['pubKutrl', 'publicBeforeContentFilter']); -dcCore::app()->addBehavior('templateBeforeValueV2', ['pubKutrl', 'templateBeforeValue']); -dcCore::app()->addBehavior('templateAfterValueV2', ['pubKutrl', 'templateAfterValue']); +dcCore::app()->addBehavior('publicBeforeContentFilterV2', ['pubKutrl', 'publicBeforeContentFilterV2']); +dcCore::app()->addBehavior('templateBeforeValueV2', ['pubKutrl', 'templateBeforeValueV2']); +dcCore::app()->addBehavior('templateAfterValueV2', ['pubKutrl', 'templateAfterValueV2']); dcCore::app()->tpl->addBlock('kutrlPageIf', ['tplKutrl', 'pageIf']); dcCore::app()->tpl->addBlock('kutrlMsgIf', ['tplKutrl', 'pageMsgIf']); @@ -50,10 +50,8 @@ class urlKutrl extends dcUrlHandlers # Redirect !!! local !!! service only public static function redirectUrl($args) { - $s = dcCore::app()->blog->settings->kUtRL; - # Not active, go to default 404 - if (!$s->kutrl_active) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active')) { self::p404(); return null; @@ -90,7 +88,7 @@ class urlKutrl extends dcUrlHandlers } # Not find, go to kutrl 404 if (false === ($url = $kut->getUrl($args))) { - //$_ctx->kutrl_msg = 'Failed to find short link.'; + //dcCore::app()->ctx->kutrl_msg = 'Failed to find short link.'; //self::pageKutrl($kut); self::kutrl404(); @@ -111,16 +109,16 @@ class urlKutrl extends dcUrlHandlers private static function pageKutrl($kut) { - $s = dcCore::app()->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); # Not active, go to default 404 - if (!$s->kutrl_active) { + if (!$s->get('kutrl_active')) { self::p404(); return null; } # Public page not active, go to kutrl 404 - if (!$s->kutrl_srv_local_public) { + if (!$s->get('kutrl_srv_local_public')) { self::kutrl404(); return null; @@ -220,7 +218,7 @@ class urlKutrl extends dcUrlHandlers protected static function kutrl404() { - if (!dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_404_active) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_srv_local_404_active')) { self::p404(); return null; @@ -257,37 +255,37 @@ class pubKutrl ]; # Disable URL shoretning on filtered tag - public static function templateBeforeValue($tag, $attr) + public static function templateBeforeValueV2($tag, $attr) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) { - return ''; + return 'ctx->__set("disable_kutrl", true); ?>'; } return null; } # Re unable it after tag - public static function templateAfterValue($tag, $attr) + public static function templateAfterValueV2($tag, $attr) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) { - return ''; + return 'ctx->__set("disable_kutrl", false); ?>'; } return null; } # Replace long urls on the fly (on filter) for default tags - public static function publicBeforeContentFilter($tag, $args) + public static function publicBeforeContentFilterV2($tag, $args) { # Unknow tag if (!in_array($tag, pubKutrl::$know_tags)) { return null; } # URL shortening is disabled by tag attribute - if (empty($GLOBALS['disable_kutrl'])) { + if (true !== dcCore::app()->ctx->__get('disable_kutrl')) { # kUtRL is not activated - if (!dcCore::app()->blog->settings->kUtRL->kutrl_active - || !dcCore::app()->blog->settings->kUtRL->kutrl_tpl_active + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_active') + || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_tpl_active') ) { return null; } @@ -311,14 +309,14 @@ class pubKutrl } } - public static function publicBeforeDocument() + public static function publicBeforeDocumentV2() { - $s = dcCore::app()->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); # Passive : all kutrl tag return long url - dcCore::app()->ctx->kutrl_passive = (bool) $s->kutrl_tpl_passive; + dcCore::app()->ctx->kutrl_passive = (bool) $s->get('kutrl_tpl_passive'); - if (!$s->kutrl_active || !$s->kutrl_tpl_service) { + if (!$s->get('kutrl_active') || !$s->get('kutrl_tpl_service')) { return null; } if (null === ($kut = kUtRL::quickPlace('tpl'))) { @@ -327,9 +325,9 @@ class pubKutrl dcCore::app()->ctx->kutrl = $kut; } - public static function publicHeadContent($core) + public static function publicHeadContent($_) { - $css = dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_css; + $css = dcCore::app()->blog->settings->get(basename(__DIR__))->get('kutrl_srv_local_css'); if ($css) { echo "\n \n" . @@ -355,7 +353,7 @@ class tplKutrl if (isset($attr['is_active'])) { $sign = (bool) $attr['is_active'] ? '' : '!'; - $if[] = $sign . 'dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_public'; + $if[] = $sign . 'dcCore::app()->blog->settings->get("kUtRL")->get("kutrl_srv_local_public")'; } if (empty($if)) { return $content; diff --git a/_uninstall.php b/_uninstall.php index 34054c7..097d17c 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -20,7 +20,7 @@ $this->addUserAction( /* action */ 'delete_all', /* ns */ - 'kUtRL', + basename(__DIR__), /* description */ __('delete all settings') ); @@ -42,7 +42,7 @@ $this->addUserAction( /* action */ 'delete', /* ns */ - 'kUtRL', + basename(__DIR__), /* description */ __('delete plugin files') ); @@ -53,7 +53,7 @@ $this->addUserAction( /* action */ 'delete', /* ns */ - 'kUtRL', + basename(__DIR__), /* description */ __('delete the version number') ); @@ -67,7 +67,7 @@ $this->addDirectAction( /* action */ 'delete_all', /* ns */ - 'kUtRL', + basename(__DIR__), /* description */ sprintf(__('delete all %s settings'), 'kUtRL') ); @@ -78,7 +78,7 @@ $this->addDirectAction( /* action */ 'delete', /* ns */ - 'kUtRL', + basename(__DIR__), /* description */ sprintf(__('delete %s version number'), 'kUtRL') ); @@ -89,7 +89,7 @@ $this->addDirectAction( /* action */ 'delete', /* ns */ - 'kUtRL', + basename(__DIR__), /* description */ sprintf(__('delete %s plugin files'), 'kUtRL') ); diff --git a/_widgets.php b/_widgets.php index bc1a02c..bbb684c 100644 --- a/_widgets.php +++ b/_widgets.php @@ -114,10 +114,10 @@ class widgetKutrl public static function publicShorten($w) { - $s = dcCore::app()->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); - if (!$s->kutrl_active - || !$s->kutrl_srv_local_public + if (!$s->get('kutrl_active') + || !$s->get('kutrl_srv_local_public') || !$w->checkHomeOnly(dcCore::app()->url->type) || dcCore::app()->url->type == 'kutrl') { return null; @@ -151,9 +151,9 @@ class widgetKutrl public static function publicRank($w) { - $s = dcCore::app()->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); - if (!$s->kutrl_active || !$w->checkHomeOnly(dcCore::app()->url->type)) { + if (!$s->get('kutrl_active') || !$w->checkHomeOnly(dcCore::app()->url->type)) { return null; } diff --git a/inc/class.kutrl.php b/inc/class.kutrl.php index d5e7aee..7bdd60e 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->kUtRL->get('kutrl_' . $place . '_service'); + $id = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('kutrl_' . $place . '_service'); if (!empty($id)) { return self::quickService($id); } diff --git a/inc/lib.kutrl.activityreport.php b/inc/lib.kutrl.activityreport.php index d637967..d1e3fba 100644 --- a/inc/lib.kutrl.activityreport.php +++ b/inc/lib.kutrl.activityreport.php @@ -16,24 +16,16 @@ if (!defined('DC_RC_PATH')) { return null; } -dcCore::app()->activityReport->addGroup('kutrl', __('Plugin kUtRL')); +dcCore::app()->__get('activityReport')->addGroup('kutrl', __('Plugin kUtRL')); # from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php -dcCore::app()->activityReport->addAction( +dcCore::app()->__get('activityReport')->addAction( 'kutrl', 'create', __('Short link creation'), __('New short link of type "%s" and hash "%s" was created.'), 'kutrlAfterCreateShortUrl', - ['kutrlActivityReportBehaviors', 'kutrlCreate'] -); - -class kutrlActivityReportBehaviors -{ - public static function kutrlCreate($rs) - { - $logs = [$rs->type,$rs->hash]; - - dcCore::app()->activityReport->addLog('kutrl', 'create', $logs); + function ($rs) { + dcCore::app()->__get('activityReport')->addLog('kutrl', 'create', [$rs->type, $rs->hash]); } -} +); diff --git a/inc/lib.kutrl.lst.php b/inc/lib.kutrl.lst.php index 46ffe0f..9ffda50 100644 --- a/inc/lib.kutrl.lst.php +++ b/inc/lib.kutrl.lst.php @@ -105,16 +105,16 @@ class kutrlLinkslist } $cols = [ - 'check' => '' . - form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) . + 'check' => '' . + form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => $checked]) . '', - 'kut_url' => '' . + 'kut_url' => '' . '' . $this->rs->kut_url . '' . '', - 'kut_hash' => '' . + 'kut_hash' => '' . $hash . '', - 'kut_dt' => '' . + 'kut_dt' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, dcCore::app()->auth->getInfo('user_tz')) . '', 'kut_service' => '' . diff --git a/inc/lib.kutrl.srv.php b/inc/lib.kutrl.srv.php index 60017ce..c627cfe 100644 --- a/inc/lib.kutrl.srv.php +++ b/inc/lib.kutrl.srv.php @@ -22,7 +22,7 @@ class kutrlService public function __construct() { - $this->settings = dcCore::app()->blog->settings->kUtRL; + $this->settings = dcCore::app()->blog->settings->get(basename(dirname(__DIR__))); $this->log = new kutrlLog(); $this->error = new dcError(); //$this->error->setHTMLFormat('%s', "%s\n"); @@ -30,24 +30,24 @@ class kutrlService $this->init(); // Force setting - $allow_external_url = $this->settings->kutrl_allow_external_url; + $allow_external_url = $this->settings->get('kutrl_allow_external_url'); $this->config['$allow_external_url'] = null === $allow_external_url ? true : $allow_external_url; $this->config = array_merge( [ - 'id' => 'undefined', - 'name' => 'undefined', - 'home' => '', + 'id' => 'undefined', + 'name' => 'undefined', + 'home' => '', 'allow_external_url' => true, 'allow_custom_hash' => false, 'allow_protocols' => ['http://'], - 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', - 'url_api' => '', - 'url_base' => '', - 'url_min_len' => 0, + 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', + 'url_api' => '', + 'url_base' => '', + 'url_min_len' => 0, ], $this->config ); diff --git a/inc/lib.wiki.kutrl.php b/inc/lib.wiki.kutrl.php index d697cba..710271f 100644 --- a/inc/lib.wiki.kutrl.php +++ b/inc/lib.wiki.kutrl.php @@ -20,12 +20,10 @@ class kutrlWiki { public static function coreInitWiki($wiki2xhtml) { - $s = dcCore::app()->blog->settings->kUtRL; - # Do nothing on comment preview and post preview if (!empty($_POST['preview']) || isset(dcCore::app()->ctx) && dcCore::app()->ctx->preview - || !$s->kutrl_active + || !dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('kutrl_active') ) { return null; } @@ -42,9 +40,7 @@ class kutrlWiki public static function transform($url, $content) { - $s = dcCore::app()->blog->settings->kUtRL; - - if (!$s->kutrl_active) { + if (!dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('kutrl_active')) { return null; } if (null === ($kut = kUtRL::quickPlace('wiki'))) { diff --git a/inc/services/class.bilbolinks.service.php b/inc/services/class.bilbolinks.service.php index 03f8d91..09dd97a 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->kutrl_srv_bilbolinks_base; + $base = (string) $this->settings->get('kutrl_srv_bilbolinks_base'); if (!empty($base) && substr($base, -1, 1) != '/') { $base .= '/'; } @@ -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 0c958b3..d3190a7 100644 --- a/inc/services/class.bitly.service.php +++ b/inc/services/class.bitly.service.php @@ -17,13 +17,13 @@ if (!defined('DC_RC_PATH')) { class bitlyKutrlService extends kutrlService { protected $config = [ - 'id' => 'bitly', - 'name' => 'bit.ly', - 'home' => 'https://bit.ly', + 'id' => 'bitly', + 'name' => 'bit.ly', + 'home' => 'https://bit.ly', - 'url_api' => 'https://api-ssl.bitly.com/v4/', - 'url_base' => 'https://bit.ly/', - 'url_min_len' => 25, + 'url_api' => 'https://api-ssl.bitly.com/v4/', + 'url_base' => 'https://bit.ly/', + 'url_min_len' => 25, 'allow_protocols' => ['http://', 'https://'], ]; diff --git a/inc/services/class.custom.service.php b/inc/services/class.custom.service.php index 6571762..9a21be5 100644 --- a/inc/services/class.custom.service.php +++ b/inc/services/class.custom.service.php @@ -23,7 +23,7 @@ class customKutrlService extends kutrlService protected function init() { - $config = unserialize(base64_decode((string) $this->settings->kutrl_srv_custom)); + $config = unserialize(base64_decode((string) $this->settings->get('kutrl_srv_custom'))); if (!is_array($config)) { $config = []; } @@ -55,7 +55,7 @@ class customKutrlService extends kutrlService 'url_param' => '', 'url_encode' => true, ]; - $config = unserialize(base64_decode((string) $this->settings->kutrl_srv_custom)); + $config = unserialize(base64_decode((string) $this->settings->get('kutrl_srv_custom'))); if (!is_array($config)) { $config = []; } diff --git a/inc/services/class.default.service.php b/inc/services/class.default.service.php index ce330c9..9214825 100644 --- a/inc/services/class.default.service.php +++ b/inc/services/class.default.service.php @@ -24,16 +24,16 @@ class defaultKutrlService extends kutrlService protected function init() { $this->config = [ - 'id' => 'default', - 'name' => 'Default', - 'home' => '', + 'id' => 'default', + 'name' => 'Default', + 'home' => '', 'url_api' => SHORTEN_SERVICE_API, 'url_base' => SHORTEN_SERVICE_BASE, 'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2, - 'url_param' => SHORTEN_SERVICE_PARAM, - 'url_encode' => SHORTEN_SERVICE_ENCODE, + 'url_param' => SHORTEN_SERVICE_PARAM, + 'url_encode' => SHORTEN_SERVICE_ENCODE, ]; } diff --git a/inc/services/class.isgd.service.php b/inc/services/class.isgd.service.php index bc5f637..9de12ad 100644 --- a/inc/services/class.isgd.service.php +++ b/inc/services/class.isgd.service.php @@ -17,9 +17,9 @@ if (!defined('DC_RC_PATH')) { class isgdKutrlService extends kutrlService { protected $config = [ - 'id' => 'isgd', - 'name' => 'is.gd', - 'home' => 'http://is.gd/', + 'id' => 'isgd', + 'name' => 'is.gd', + 'home' => 'http://is.gd/', 'url_api' => 'http://is.gd/api.php', 'url_base' => 'http://is.gd/', diff --git a/inc/services/class.local.service.php b/inc/services/class.local.service.php index f332df8..588e2ef 100644 --- a/inc/services/class.local.service.php +++ b/inc/services/class.local.service.php @@ -17,16 +17,16 @@ if (!defined('DC_RC_PATH')) { class localKutrlService extends kutrlService { protected $config = [ - 'id' => 'local', - 'name' => 'kUtRL', - 'home' => 'https://github.com/JcDenis/kUtRL', + 'id' => 'local', + 'name' => 'kUtRL', + 'home' => 'https://github.com/JcDenis/kUtRL', 'allow_custom_hash' => true, ]; protected function init() { - $protocols = (string) $this->settings->kutrl_srv_local_protocols; + $protocols = (string) $this->settings->get('kutrl_srv_local_protocols'); $this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols); $this->config['url_base'] = dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/'; @@ -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->kutrl_srv_local_css), '', '2') . + form::textarea('kutrl_srv_local_css', 50, 3, html::escapeHTML($this->settings->get('kutrl_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.shortto.service.php b/inc/services/class.shortto.service.php index 7f91268..3cd7f60 100644 --- a/inc/services/class.shortto.service.php +++ b/inc/services/class.shortto.service.php @@ -17,9 +17,9 @@ if (!defined('DC_RC_PATH')) { class shorttoKutrlService extends kutrlService { protected $config = [ - 'id' => 'shortto', - 'name' => 'short.to', - 'home' => 'http://short.to', + 'id' => 'shortto', + 'name' => 'short.to', + 'home' => 'http://short.to', 'url_api' => 'http://short.to/s.txt', 'url_base' => 'http://short.to/', diff --git a/inc/services/class.supr.service.php b/inc/services/class.supr.service.php index f8b1bdb..81c14ce 100644 --- a/inc/services/class.supr.service.php +++ b/inc/services/class.supr.service.php @@ -17,9 +17,9 @@ if (!defined('DC_RC_PATH')) { class suprKutrlService extends kutrlService { protected $config = [ - 'id' => 'supr', - 'name' => 'su.pr StumbleUpon', - 'home' => 'http://su.pr', + 'id' => 'supr', + 'name' => 'su.pr StumbleUpon', + 'home' => 'http://su.pr', 'url_api' => 'http://su.pr/api/', 'url_base' => 'http://su.pr/', @@ -35,8 +35,8 @@ class suprKutrlService extends kutrlService protected function init() { - $this->args['login'] = $this->settings->kutrl_srv_supr_login; - $this->args['apiKey'] = $this->settings->kutrl_srv_supr_apikey; + $this->args['login'] = $this->settings->get('kutrl_srv_supr_login'); + $this->args['apiKey'] = $this->settings->get('kutrl_srv_supr_apikey'); } public function saveSettings() @@ -49,13 +49,13 @@ class suprKutrlService extends kutrlService { 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 09e1a9d..6a1d36a 100644 --- a/inc/services/class.trim.service.php +++ b/inc/services/class.trim.service.php @@ -17,9 +17,9 @@ if (!defined('DC_RC_PATH')) { class trimKutrlService extends kutrlService { protected $config = [ - 'id' => 'trim', - 'name' => 'tr.im', - 'home' => 'http://tr.im', + 'id' => 'trim', + 'name' => 'tr.im', + 'home' => 'http://tr.im', 'url_api' => 'http://api.tr.im/v1/', 'url_base' => 'http://tr.im/', @@ -35,10 +35,10 @@ class trimKutrlService extends kutrlService protected function init() { - $this->args['username'] = $this->settings->kutrl_srv_trim_username; - $this->args['password'] = $this->settings->kutrl_srv_trim_password; + $this->args['username'] = $this->settings->get('kutrl_srv_trim_username'); + $this->args['password'] = $this->settings->get('kutrl_srv_trim_password'); - $this->api_rate_time = (int) $this->settings->kutrl_srv_trim_apiratetime; + $this->api_rate_time = (int) $this->settings->get('kutrl_srv_trim_apiratetime'); } public function saveSettings() @@ -51,13 +51,13 @@ class trimKutrlService extends kutrlService { echo '

' . '

' . __('This is your login to sign up to tr.im.') . '

' . '

' . '

' . __('This is your password to sign up to tr.im.') . diff --git a/inc/services/class.yourls.service.php b/inc/services/class.yourls.service.php index b14eae2..69befe9 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->kutrl_srv_yourls_username; - $this->args['password'] = $this->settings->kutrl_srv_yourls_password; + $this->args['username'] = $this->settings->get('kutrl_srv_yourls_username'); + $this->args['password'] = $this->settings->get('kutrl_srv_yourls_password'); - $base = (string) $this->settings->kutrl_srv_yourls_base; + $base = (string) $this->settings->get('kutrl_srv_yourls_base'); //if (!empty($base) && substr($base,-1,1) != '/') $base .= '/'; $this->config['url_api'] = $base; @@ -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 149d85d..d971de9 100644 --- a/index.php +++ b/index.php @@ -175,7 +175,7 @@ if ($part == 'link') { ]) . dcPage::notices(); - if (null === $kut) { + if (!isset($kut) || null === $kut) { echo '

' . __('You must set an admin service.') . '

'; } else { echo '