From 3a9e90ac9f0696f880a0a633b3090d6efe782237 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 20 Nov 2022 17:15:36 +0100 Subject: [PATCH] prepare to DC 2.24 --- _admin.php | 188 ++++++++++-------- _config.php | 36 ++-- _define.php | 18 +- _install.php | 20 +- _prepend.php | 66 +++---- _public.php | 231 +++++++++++----------- _widgets.php | 42 ++-- inc/class.kutrl.php | 20 +- inc/lib.kutrl.activityreport.php | 6 +- inc/lib.kutrl.log.php | 12 +- inc/lib.kutrl.lst.php | 14 +- inc/lib.kutrl.srv.php | 20 +- inc/lib.wiki.kutrl.php | 14 +- inc/patch.dcminiurl.php | 18 +- inc/services/class.bilbolinks.service.php | 2 +- inc/services/class.bitly.service.php | 2 +- inc/services/class.custom.service.php | 10 +- inc/services/class.default.service.php | 2 +- inc/services/class.googl.service.php | 2 +- inc/services/class.isgd.service.php | 2 +- inc/services/class.local.service.php | 7 +- inc/services/class.shortto.service.php | 2 +- inc/services/class.supr.service.php | 4 +- inc/services/class.trim.service.php | 4 +- inc/services/class.yourls.service.php | 4 +- index.php | 58 +++--- locales/en/resources.php | 2 +- locales/fr/resources.php | 2 +- 28 files changed, 403 insertions(+), 405 deletions(-) diff --git a/_admin.php b/_admin.php index 40e1404..342f7b0 100644 --- a/_admin.php +++ b/_admin.php @@ -14,39 +14,38 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$core->blog->settings->addNamespace('kUtRL'); +dcCore::app()->blog->settings->addNamespace('kUtRL'); -require_once dirname(__FILE__) . '/_widgets.php'; +require_once __DIR__ . '/_widgets.php'; # Plugin menu -$_menu['Plugins']->addItem( +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Links shortener'), - $core->adminurl->get('admin.plugin.kUtRL'), + dcCore::app()->adminurl->get('admin.plugin.kUtRL'), dcPage::getPF('kUtRL/icon.png'), - preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - $core->auth->check('admin', $core->blog->id) + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id) ); # Admin behaviors -if ($core->blog->settings->kUtRL->kutrl_active) { - $core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']); - $core->addBehavior('adminColumnsLists', ['adminKutrl', 'adminColumnsLists']); - $core->addBehavior('adminFiltersLists', ['adminKutrl', 'adminFiltersLists']); - $core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); - $core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']); - $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url - $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostCreate']); // create new short url - $core->addBehavior('adminAfterPostCreate', ['adminKutrl', 'adminAfterPostCreate']); - $core->addBehavior('adminBeforePostDelete', ['adminKutrl', 'adminBeforePostDelete']); - $core->addBehavior('adminPostsActionsCombo', ['adminKutrl', 'adminPostsActionsCombo']); - $core->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']); +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']); + dcCore::app()->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); + dcCore::app()->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']); + dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url + dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostCreate']); // create new short url + dcCore::app()->addBehavior('adminAfterPostCreate', ['adminKutrl', 'adminAfterPostCreate']); + dcCore::app()->addBehavior('adminBeforePostDelete', ['adminKutrl', 'adminBeforePostDelete']); + dcCore::app()->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']); } -$core->addBehavior('exportFull', ['backupKutrl', 'exportFull']); -$core->addBehavior('exportSingle', ['backupKutrl', 'exportSingle']); -$core->addBehavior('importInit', ['backupKutrl', 'importInit']); -$core->addBehavior('importSingle', ['backupKutrl', 'importSingle']); -$core->addBehavior('importFull', ['backupKutrl', 'importFull']); +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']); # Admin behaviors class class adminKutrl @@ -57,44 +56,44 @@ class adminKutrl __('Date') => 'kut_dt', __('Short link') => 'kut_hash', __('Long link') => 'kut_url', - __('Service') => 'kut_service' + __('Service') => 'kut_service', ]; } - public static function antispamDashboardFavorites(dcCore $core, $favs) + public static function antispamDashboardFavorites(dcFavorites $favs) { $favs->register( 'kUtRL', [ 'title' => __('Links shortener'), - 'url' => $core->adminurl->get('admin.plugin.kUtRL'), + 'url' => dcCore::app()->adminurl->get('admin.plugin.kUtRL'), 'small-icon' => dcPage::getPF('kUtRL/icon.png'), 'large-icon' => dcPage::getPF('kUtRL/icon-b.png'), - 'permissions' => 'admin' + 'permissions' => 'admin', ] ); } - public static function adminColumnsLists(dcCore $core, $cols) + public static function adminColumnsLists($cols) { $cols['kUtRL'] = [ __('Links shortener'), [ 'kut_hash' => [true, __('Hash')], 'kut_dt' => [true, __('Date')], - 'kut_service' => [true, __('Service')] - ] + 'kut_service' => [true, __('Service')], + ], ]; } - public static function adminFiltersLists(dcCore $core, $sorts) + public static function adminFiltersLists($sorts) { $sorts['kUtRL'] = [ __('Links shortener'), self::sortbyCombo(), 'kut_dt', 'desc', - [__('links per page'), 30] + [__('links per page'), 30], ]; } @@ -105,13 +104,12 @@ class adminKutrl public static function adminPostFormItems($main_items, $sidebar_items, $post) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (!$s->kutrl_active || !$s->kutrl_admin_service) { return null; } - if (null === ($kut = kutrl::quickPlace('admin'))) { + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } @@ -165,14 +163,13 @@ class adminKutrl public static function adminAfterPostUpdate($cur, $post_id) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; # Create: see adminAfterPostCreate if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) { return null; } - if (null === ($kut = kutrl::quickPlace('admin'))) { + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } if (empty($_POST['kutrl_old_post_url'])) { @@ -185,7 +182,7 @@ class adminKutrl return null; } - $rs = $core->blog->getPosts(['post_id' => $post_id]); + $rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]); if ($rs->isEmpty()) { return null; } @@ -208,24 +205,23 @@ class adminKutrl # ex: Send new url to messengers if (!empty($rs)) { - $core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title); + dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, $title); } } } public static function adminAfterPostCreate($cur, $post_id) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (empty($_POST['kutrl_create']) || !$s->kutrl_active) { return null; } - if (null === ($kut = kutrl::quickPlace('admin'))) { + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } - $rs = $core->blog->getPosts(['post_id' => $post_id]); + $rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]); if ($rs->isEmpty()) { return null; } @@ -239,23 +235,22 @@ class adminKutrl # ex: Send new url to messengers if (!empty($rs)) { - $core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title); + dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, $title); } } public static function adminBeforePostDelete($post_id) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (!$s->kutrl_active) { return null; } - if (null === ($kut = kutrl::quickPlace('admin'))) { + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } - $rs = $core->blog->getPosts(['post_id' => $post_id]); + $rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]); if ($rs->isEmpty()) { return null; } @@ -263,75 +258,102 @@ class adminKutrl $kut->remove($rs->getURL()); } - public static function adminPostsActionsCombo($args) + public static function adminPostsActions(dcPostsActions $pa) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (!$s->kutrl_active - || !$core->auth->check('admin', $core->blog->id)) { + || !dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)) { return null; } - $args[0][__('Links shortener')][__('Create short link')] = 'kutrl_create'; - $args[0][__('Links shortener')][__('Delete short link')] = 'kutrl_delete'; + $pa->addAction( + [__('Links shortener') => [__('Create short link') => 'kutrl_create']], + ['adminKutrl', 'callbackCreate'] + ); + $pa->addAction( + [__('Links shortener') => [__('Delete short link') => 'kutrl_delete']], + ['adminKutrl', 'callbackDelete'] + ); } - public static function adminPostsActions(dcCore $core, $posts, $action, $redir) + public static function callbackCreate(dcPostsActions $pa, ArrayObject $post) { - if ($action != 'kutrl_create' - && $action != 'kutrl_delete') { - return null; - } - $s = $core->blog->settings->kUtRL; - if (!$s->kutrl_active) { - return null; - } - if (null === ($kut = kutrl::quickPlace('admin'))) { + if (null === ($kut = kUtRL::quickPlace('admin'))) { return null; } + # No entry + $posts_ids = $pa->getIDs(); + if (empty($posts_ids)) { + throw new Exception(__('No entry selected')); + } + + # No right + if (!dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)) { + throw new Exception(__('No enough right')); + } + + # retrieve posts info and create hash + $posts = dcCore::app()->blog->getPosts(['post_id' => $posts_ids]); while ($posts->fetch()) { - $url = $posts->getURL(); - - if ($action == 'kutrl_create') { - $kut->hash($url); - } - if ($action == 'kutrl_delete') { - $kut->remove($url); - } + $kut->hash($posts->getURL()); } - $core->blog->triggerBlog(); - http::redirect($redir . '&done=1'); + + dcAdminNotices::addSuccessNotice(__('Posts short links have been created.')); + $pa->redirect(true); + } + + public static function callbackDelete(dcPostsActions $pa, ArrayObject $post) + { + # No entry + $posts_ids = $pa->getIDs(); + if (empty($posts_ids)) { + throw new Exception(__('No entry selected')); + } + + # No right + if (!dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)) { + throw new Exception(__('No enough right')); + } + + # retrieve posts info and create hash + $posts = dcCore::app()->blog->getPosts(['post_id' => $posts_ids]); + while ($posts->fetch()) { + $kut->remove($posts->getURL()); + } + + dcAdminNotices::addSuccessNotice(__('Posts short links have been created.')); + $pa->redirect(true); } } # Import/export behaviors for Import/export plugin class backupKutrl { - public static function exportSingle($core, $exp, $blog_id) + public static function exportSingle($exp, $blog_id) { $exp->export( 'kutrl', 'SELECT kut_id, blog_id, kut_service, kut_type, ' . 'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' . - 'FROM ' . $core->prefix . 'kutrl ' . + 'FROM ' . dcCore::app()->prefix . 'kutrl ' . "WHERE blog_id = '" . $blog_id . "' " ); } - public static function exportFull($core, $exp) + public static function exportFull($exp) { $exp->exportTable('kutrl'); } - public static function importInit($bk, $core) + public static function importInit($bk) { - $bk->cur_kutrl = $core->con->openCursor($core->prefix . 'kutrl'); - $bk->kutrl = new kutrlLog($core); + $bk->cur_kutrl = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'kutrl'); + $bk->kutrl = new kutrlLog(); } - public static function importSingle($line, $bk, $core) + public static function importSingle($line, $bk) { if ($line->__name == 'kutrl') { # Do nothing if str/type exists ! @@ -341,7 +363,7 @@ class backupKutrl } } - public static function importFull($line, $bk, $core) + public static function importFull($line, $bk) { if ($line->__name == 'kutrl') { $bk->cur_kutrl->clean(); diff --git a/_config.php b/_config.php index 6c7d405..61d3d62 100644 --- a/_config.php +++ b/_config.php @@ -15,18 +15,18 @@ if (!defined('DC_CONTEXT_ADMIN')) { } # Check user perms -dcPage::check('admin'); +dcPage::check(dcAuth::PERMISSION_ADMIN); # Settings -$s = $core->blog->settings->kUtRL; +$s = dcCore::app()->blog->settings->kUtRL; # Default values $img_green = 'ok'; $img_red = 'fail'; $services_combo = []; -foreach (kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); +foreach (kUtRL::getServices() as $service_id => $service) { + $o = new $service(); $services_combo[__($o->name)] = $o->id; } $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); @@ -66,23 +66,23 @@ if (!empty($_POST['save'])) { $s->put('kutrl_admin_entry_default', $s_admin_entry_default); # services - foreach (kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); + foreach (kUtRL::getServices() as $service_id => $service) { + $o = new $service(); $o->saveSettings(); } - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Configuration successfully updated.') ); - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugins', - ['module' => 'kUtRL', 'conf' => 1, 'chk' => 1, 'redir' => $list->getRedir()] + ['module' => 'kUtRL', 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] ); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } @@ -121,7 +121,7 @@ __('Create short link for new entries') . '

' . __('Default services') . '

' . __('Service to use in this admin page and on edit page of an entry.') . '

' . __('Service to use on third part plugins.') . '

' . __('Shorten links automatically when using template value like "EntryKutrl".') . '

' . __('List of services you can use to shorten links with pkugin kUtRL.') . '

'; -foreach (kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); +foreach (kUtRL::getServices() as $service_id => $service) { + $o = new $service(); echo '
' . $o->name . '
'; @@ -180,7 +180,7 @@ foreach (kutrl::getServices($core) as $service_id => $service) { $img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name); } } catch (Exception $e) { - $core->error->add(sprintf(__('Failed to test service %s: %s'), $o->name, $e->getMessage())); + dcCore::app()->error->add(sprintf(__('Failed to test service %s: %s'), $o->name, $e->getMessage())); } echo sprintf('

%s

', $img_chk) . $o->error->toHTML(); } diff --git a/_define.php b/_define.php index 25f7a93..9100e7c 100644 --- a/_define.php +++ b/_define.php @@ -18,13 +18,17 @@ $this->registerModule( 'Links shortener', 'Use, create and serve short url on your blog', 'Jean-Christian Denis and contributors', - '2021.11.06', + '2022.11.12', [ - 'requires' => [['core', '2.20']], - 'permissions' => 'usage,contentadmin,admin', - 'type' => 'plugin', - 'support' => 'https://github.com/JcDenis/kUtRL', - 'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml' + 'requires' => [['core', '2.24']], + 'permissions' => dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_USAGE, + dcAuth::PERMISSION_CONTENT_ADMIN, + dcAuth::PERMISSION_ADMIN, + ]), + 'type' => 'plugin', + 'support' => 'https://github.com/JcDenis/kUtRL', + 'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL', + 'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml', ] ); diff --git a/_install.php b/_install.php index e4304b1..969a98b 100644 --- a/_install.php +++ b/_install.php @@ -15,8 +15,8 @@ if (!defined('DC_CONTEXT_ADMIN')) { } # Get new version -$new_version = $core->plugins->moduleInfo('kUtRL', 'version'); -$old_version = $core->getVersion('kUtRL'); +$new_version = dcCore::app()->plugins->moduleInfo('kUtRL', 'version'); +$old_version = dcCore::app()->getVersion('kUtRL'); # Compare versions if (version_compare($old_version, $new_version, '>=')) { @@ -26,7 +26,7 @@ if (version_compare($old_version, $new_version, '>=')) { # Install or update try { # Table - $t = new dbStruct($core->con, $core->prefix); + $t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $t->kutrl ->kut_id('bigint', 0, false) ->blog_id('varchar', 32, false) @@ -44,12 +44,12 @@ try { ->index('idx_kut_service', 'btree', 'kut_service') ->index('idx_kut_type', 'btree', 'kut_type'); - $ti = new dbStruct($core->con, $core->prefix); + $ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $changes = $ti->synchronize($t); # Settings - $core->blog->settings->addNamespace('kUtRL'); - $s = $core->blog->settings->kUtRL; + dcCore::app()->blog->settings->addNamespace('kUtRL'); + $s = dcCore::app()->blog->settings->kUtRL; $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); @@ -74,16 +74,16 @@ try { $s->put('kutrl_srv_yourls_password', '', 'string', 'User password to YOURLS service', false, true); # Version - $core->setVersion('kUtRL', $new_version); + dcCore::app()->setVersion('kUtRL', $new_version); # Get dcMiniUrl records as this plugin do the same - if ($core->plugins->moduleExists('dcMiniUrl')) { - require_once dirname(__FILE__) . '/inc/patch.dcminiurl.php'; + if (dcCore::app()->plugins->moduleExists('dcMiniUrl')) { + require_once __DIR__ . '/inc/patch.dcminiurl.php'; } return true; } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } return false; diff --git a/_prepend.php b/_prepend.php index a728060..0055170 100644 --- a/_prepend.php +++ b/_prepend.php @@ -32,66 +32,66 @@ if (!defined('SHORTEN_SERVICE_ENCODE')) { } # Main class -$d = dirname(__FILE__) . '/inc/'; -$__autoload['kutrl'] = $d . 'class.kutrl.php'; -$__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php'; -$__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php'; -$__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php'; +$d = __DIR__ . '/inc/'; +Clearbricks::lib()->autoload(['kUtRL' => $d . 'class.kutrl.php']); +Clearbricks::lib()->autoload(['kutrlService' => $d . 'lib.kutrl.srv.php']); +Clearbricks::lib()->autoload(['kutrlLog' => $d . 'lib.kutrl.log.php']); +Clearbricks::lib()->autoload(['kutrlLinkslist' => $d . 'lib.kutrl.lst.php']); # Services -$__autoload['defaultKutrlService'] = $d . 'services/class.default.service.php'; -$core->addBehavior('kutrlService', function () { return ['default','defaultKutrlService']; }); +Clearbricks::lib()->autoload(['defaultKutrlService' => $d . 'services/class.default.service.php']); +dcCore::app()->addBehavior('kutrlService', function () { return ['default','defaultKutrlService']; }); if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) { - $__autoload['customKutrlService'] = $d . 'services/class.custom.service.php'; - $core->addBehavior('kutrlService', function () { return ['custom','customKutrlService']; }); + Clearbricks::lib()->autoload(['customKutrlService' => $d . 'services/class.custom.service.php']); + dcCore::app()->addBehavior('kutrlService', function () { return ['custom','customKutrlService']; }); } if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) { - $__autoload['localKutrlService'] = $d . 'services/class.local.service.php'; - $core->addBehavior('kutrlService', function () { return ['local','localKutrlService']; }); + Clearbricks::lib()->autoload(['localKutrlService' => $d . 'services/class.local.service.php']); + dcCore::app()->addBehavior('kutrlService', function () { return ['local','localKutrlService']; }); } if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) { - $__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php'; - $core->addBehavior('kutrlService', function () { return ['bilbolinks','bilbolinksKutrlService']; }); + Clearbricks::lib()->autoload(['bilbolinksKutrlService' => $d . 'services/class.bilbolinks.service.php']); + dcCore::app()->addBehavior('kutrlService', function () { return ['bilbolinks','bilbolinksKutrlService']; }); } if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) { - $__autoload['bitlyKutrlService'] = $d . 'services/class.bitly.service.php'; - $core->addBehavior('kutrlService', function () { return ['bitly','bitlyKutrlService']; }); + Clearbricks::lib()->autoload(['bitlyKutrlService' => $d . 'services/class.bitly.service.php']); + dcCore::app()->addBehavior('kutrlService', function () { return ['bitly','bitlyKutrlService']; }); } //if (!defined('SHORTEN_SERVICE_DISABLE_GOOGL')) { -// $__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php'; -// $core->addBehavior('kutrlService', function() { return ["googl","googlKutrlService"]; } ); +// Clearbricks::lib()->autoload(['googlKutrlService' => $d . 'services/class.googl.service.php']); +// dcCore::app()->addBehavior('kutrlService', function() { return ["googl","googlKutrlService"]; } ); //} if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) { - $__autoload['isgdKutrlService'] = $d . 'services/class.isgd.service.php'; - $core->addBehavior('kutrlService', function () { return ['isgd','isgdKutrlService']; }); + Clearbricks::lib()->autoload(['isgdKutrlService' => $d . 'services/class.isgd.service.php']); + dcCore::app()->addBehavior('kutrlService', function () { return ['isgd','isgdKutrlService']; }); } //if (!defined('SHORTEN_SERVICE_DISABLE_SHORTTO')) { -// $__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php'; -// $core->addBehavior('kutrlService', function() { return ["shortto","shorttoKutrlService"]; } ); +// Clearbricks::lib()->autoload(['shorttoKutrlService' => $d . 'services/class.shortto.service.php']); +// dcCore::app()->addBehavior('kutrlService', function() { return ["shortto","shorttoKutrlService"]; } ); //} //if (!defined('SHORTEN_SERVICE_DISABLE_TRIM')) { -// $__autoload['trimKutrlService'] = $d . 'services/class.trim.service.php'; -// $core->addBehavior('kutrlService', function() { return ["trim","trimKutrlService"]; } ); +// Clearbricks::lib()->autoload(['trimKutrlService' => $d . 'services/class.trim.service.php']); +// dcCore::app()->addBehavior('kutrlService', function() { return ["trim","trimKutrlService"]; } ); //} if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) { - $__autoload['yourlsKutrlService'] = $d . 'services/class.yourls.service.php'; - $core->addBehavior('kutrlService', function () { return ['yourls','yourlsKutrlService']; }); + Clearbricks::lib()->autoload(['yourlsKutrlService' => $d . 'services/class.yourls.service.php']); + dcCore::app()->addBehavior('kutrlService', function () { return ['yourls','yourlsKutrlService']; }); } //if (!defined('SHORTEN_SERVICE_DISABLE_SUPR')) { -// $__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php'; -// $core->addBehavior('kutrlService', function() { return ["supr","suprKutrlService"]; } ); +// Clearbricks::lib()->autoload(['suprKutrlService' => $d . 'services/class.supr.service.php']); +// dcCore::app()->addBehavior('kutrlService', function() { return ["supr","suprKutrlService"]; } ); //} # Shorten url passed through wiki functions -$__autoload['kutrlWiki'] = $d . 'lib.wiki.kutrl.php'; -$core->addBehavior('coreInitWikiPost', ['kutrlWiki','coreInitWiki']); -$core->addBehavior('coreInitWikiComment', ['kutrlWiki','coreInitWiki']); -$core->addBehavior('coreInitWikiSimpleComment', ['kutrlWiki','coreInitWiki']); +Clearbricks::lib()->autoload(['kutrlWiki' => $d . 'lib.wiki.kutrl.php']); +dcCore::app()->addBehavior('coreInitWikiPost', ['kutrlWiki','coreInitWiki']); +dcCore::app()->addBehavior('coreInitWikiComment', ['kutrlWiki','coreInitWiki']); +dcCore::app()->addBehavior('coreInitWikiSimpleComment', ['kutrlWiki','coreInitWiki']); # Public page -$core->url->register('kutrl', 'go', '^go(/(.*?)|)$', ['urlKutrl', 'redirectUrl']); +dcCore::app()->url->register('kutrl', 'go', '^go(/(.*?)|)$', ['urlKutrl', 'redirectUrl']); # Add kUtRL events on plugin activityReport -if (defined('ACTIVITY_REPORT')) { +if (defined('ACTIVITY_REPORT_V2')) { require_once $d . 'lib.kutrl.activityreport.php'; } diff --git a/_public.php b/_public.php index 69db51f..63a40ca 100644 --- a/_public.php +++ b/_public.php @@ -14,44 +14,43 @@ if (!defined('DC_RC_PATH')) { return null; } -require_once dirname(__FILE__) . '/_widgets.php'; +require_once __DIR__ . '/_widgets.php'; -$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates'); +dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates'); -$core->addBehavior('publicBeforeDocument', ['pubKutrl', 'publicBeforeDocument']); -$core->addBehavior('publicHeadContent', ['pubKutrl', 'publicHeadContent']); -$core->addBehavior('publicBeforeContentFilter', ['pubKutrl', 'publicBeforeContentFilter']); -$core->addBehavior('templateBeforeValue', ['pubKutrl', 'templateBeforeValue']); -$core->addBehavior('templateAfterValue', ['pubKutrl', 'templateAfterValue']); +dcCore::app()->addBehavior('publicBeforeDocumentV2', ['pubKutrl', 'publicBeforeDocument']); +dcCore::app()->addBehavior('publicHeadContent', ['pubKutrl', 'publicHeadContent']); +dcCore::app()->addBehavior('publicBeforeContentFilterV2', ['pubKutrl', 'publicBeforeContentFilter']); +dcCore::app()->addBehavior('templateBeforeValueV2', ['pubKutrl', 'templateBeforeValue']); +dcCore::app()->addBehavior('templateAfterValueV2', ['pubKutrl', 'templateAfterValue']); -$core->tpl->addBlock('kutrlPageIf', ['tplKutrl', 'pageIf']); -$core->tpl->addBlock('kutrlMsgIf', ['tplKutrl', 'pageMsgIf']); +dcCore::app()->tpl->addBlock('kutrlPageIf', ['tplKutrl', 'pageIf']); +dcCore::app()->tpl->addBlock('kutrlMsgIf', ['tplKutrl', 'pageMsgIf']); -$core->tpl->addValue('kutrlPageURL', ['tplKutrl', 'pageURL']); -$core->tpl->addValue('kutrlMsg', ['tplKutrl', 'pageMsg']); -$core->tpl->addValue('kutrlHumanField', ['tplKutrl', 'humanField']); -$core->tpl->addValue('kutrlHumanFieldProtect', ['tplKutrl', 'humanFieldProtect']); +dcCore::app()->tpl->addValue('kutrlPageURL', ['tplKutrl', 'pageURL']); +dcCore::app()->tpl->addValue('kutrlMsg', ['tplKutrl', 'pageMsg']); +dcCore::app()->tpl->addValue('kutrlHumanField', ['tplKutrl', 'humanField']); +dcCore::app()->tpl->addValue('kutrlHumanFieldProtect', ['tplKutrl', 'humanFieldProtect']); -$core->tpl->addBlock('AttachmentKutrlIf', ['tplKutrl', 'AttachmentKutrlIf']); -$core->tpl->addValue('AttachmentKutrl', ['tplKutrl', 'AttachmentKutrl']); -$core->tpl->addBlock('MediaKutrlIf', ['tplKutrl', 'MediaKutrlIf']); -$core->tpl->addValue('MediaKutrl', ['tplKutrl', 'MediaKutrl']); -$core->tpl->addBlock('EntryAuthorKutrlIf', ['tplKutrl', 'EntryAuthorKutrlIf']); -$core->tpl->addValue('EntryAuthorKutrl', ['tplKutrl', 'EntryAuthorKutrl']); -$core->tpl->addBlock('EntryKutrlIf', ['tplKutrl', 'EntryKutrlIf']); -$core->tpl->addValue('EntryKutrl', ['tplKutrl', 'EntryKutrl']); -$core->tpl->addBlock('CommentAuthorKutrlIf', ['tplKutrl', 'CommentAuthorKutrlIf']); -$core->tpl->addValue('CommentAuthorKutrl', ['tplKutrl', 'CommentAuthorKutrl']); -$core->tpl->addBlock('CommentPostKutrlIf', ['tplKutrl', 'CommentPostKutrlIf']); -$core->tpl->addValue('CommentPostKutrl', ['tplKutrl', 'CommentPostKutrl']); +dcCore::app()->tpl->addBlock('AttachmentKutrlIf', ['tplKutrl', 'AttachmentKutrlIf']); +dcCore::app()->tpl->addValue('AttachmentKutrl', ['tplKutrl', 'AttachmentKutrl']); +dcCore::app()->tpl->addBlock('MediaKutrlIf', ['tplKutrl', 'MediaKutrlIf']); +dcCore::app()->tpl->addValue('MediaKutrl', ['tplKutrl', 'MediaKutrl']); +dcCore::app()->tpl->addBlock('EntryAuthorKutrlIf', ['tplKutrl', 'EntryAuthorKutrlIf']); +dcCore::app()->tpl->addValue('EntryAuthorKutrl', ['tplKutrl', 'EntryAuthorKutrl']); +dcCore::app()->tpl->addBlock('EntryKutrlIf', ['tplKutrl', 'EntryKutrlIf']); +dcCore::app()->tpl->addValue('EntryKutrl', ['tplKutrl', 'EntryKutrl']); +dcCore::app()->tpl->addBlock('CommentAuthorKutrlIf', ['tplKutrl', 'CommentAuthorKutrlIf']); +dcCore::app()->tpl->addValue('CommentAuthorKutrl', ['tplKutrl', 'CommentAuthorKutrl']); +dcCore::app()->tpl->addBlock('CommentPostKutrlIf', ['tplKutrl', 'CommentPostKutrlIf']); +dcCore::app()->tpl->addValue('CommentPostKutrl', ['tplKutrl', 'CommentPostKutrl']); class urlKutrl extends dcUrlHandlers { # Redirect !!! local !!! service only public static function redirectUrl($args) { - global $core, $_ctx; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; # Not active, go to default 404 if (!$s->kutrl_active) { @@ -66,16 +65,16 @@ class urlKutrl extends dcUrlHandlers return null; } - $args = $m[3] ?? ''; - $_ctx->kutrl_msg = ''; - $_ctx->kutrl_hmf = hmfKutrl::create(); - $_ctx->kutrl_hmfp = hmfKutrl::protect($_ctx->kutrl_hmf); + $args = $m[3] ?? ''; + dcCore::app()->ctx->kutrl_msg = ''; + dcCore::app()->ctx->kutrl_hmf = hmfKutrl::create(); + dcCore::app()->ctx->kutrl_hmfp = hmfKutrl::protect(dcCore::app()->ctx->kutrl_hmf); - $kut = new localKutrlService($core); + $kut = new localKutrlService(); # Nothing on url if ($m[1] == '/') { - $_ctx->kutrl_msg = 'No link given.'; + dcCore::app()->ctx->kutrl_msg = 'No link given.'; } # find suffix on redirect url $suffix = ''; @@ -104,7 +103,7 @@ class urlKutrl extends dcUrlHandlers return null; } - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); http::redirect($url . $suffix); return null; @@ -112,8 +111,7 @@ class urlKutrl extends dcUrlHandlers private static function pageKutrl($kut) { - global $core, $_ctx; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; # Not active, go to default 404 if (!$s->kutrl_active) { @@ -128,7 +126,7 @@ class urlKutrl extends dcUrlHandlers return null; } # Validation form - $url = !empty($_POST['longurl']) ? trim($core->con->escape($_POST['longurl'])) : ''; + $url = !empty($_POST['longurl']) ? trim(dcCore::app()->con->escape($_POST['longurl'])) : ''; if (!empty($url)) { $hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!'; $hmfu = !empty($_POST['hmfp']) ? hmfKutrl::unprotect($_POST['hmfp']) : '?'; @@ -136,45 +134,45 @@ class urlKutrl extends dcUrlHandlers $err = false; if (!$err) { if ($hmf != $hmfu) { - $err = true; - $_ctx->kutrl_msg = __('Failed to verify protected field.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('Failed to verify protected field.'); } } if (!$err) { if (!$kut->testService()) { - $err = true; - $_ctx->kutrl_msg = __('Service is not well configured.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('Service is not well configured.'); } } if (!$err) { if (!$kut->isValidUrl($url)) { - $err = true; - $_ctx->kutrl_msg = __('This string is not a valid URL.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('This string is not a valid URL.'); } } if (!$err) { if (!$kut->isLongerUrl($url)) { - $err = true; - $_ctx->kutrl_msg = __('This link is too short.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('This link is too short.'); } } if (!$err) { if (!$kut->isProtocolUrl($url)) { - $err = true; - $_ctx->kutrl_msg = __('This type of link is not allowed.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('This type of link is not allowed.'); } } if (!$err) { if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) { - $err = true; - $_ctx->kutrl_msg = __('Short links are limited to this blog URL.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('Short links are limited to this blog URL.'); } } if (!$err) { if ($kut->isServiceUrl($url)) { - $err = true; - $_ctx->kutrl_msg = __('This link is already a short link.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('This link is already a short link.'); } } if (!$err) { @@ -184,7 +182,7 @@ class urlKutrl extends dcUrlHandlers $url = $rs->url; $new_url = $kut->url_base . $rs->hash; - $_ctx->kutrl_msg = sprintf( + dcCore::app()->ctx->kutrl_msg = sprintf( __('Short link for %s is %s'), html::escapeHTML($url), '' . $new_url . '' @@ -193,28 +191,28 @@ class urlKutrl extends dcUrlHandlers } if (!$err) { if (false === ($rs = $kut->hash($url))) { - $err = true; - $_ctx->kutrl_msg = __('Failed to create short link.'); + $err = true; + dcCore::app()->ctx->kutrl_msg = __('Failed to create short link.'); } else { $url = $rs->url; $new_url = $kut->url_base . $rs->hash; - $_ctx->kutrl_msg = sprintf( + dcCore::app()->ctx->kutrl_msg = sprintf( __('Short link for %s is %s'), html::escapeHTML($url), '' . $new_url . '' ); - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); # ex: Send new url to messengers if (!empty($rs)) { - $core->callBehavior('publicAfterKutrlCreate', $core, $rs, __('New public short URL')); + dcCore::app()->callBehavior('publicAfterKutrlCreate', $rs, __('New public short URL')); } } } } - $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates'); + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates'); self::serveDocument('kutrl.html'); return null; @@ -222,28 +220,24 @@ class urlKutrl extends dcUrlHandlers protected static function kutrl404() { - global $core; - - if (!$core->blog->settings->kUtRL->kutrl_srv_local_404_active) { + if (!dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_404_active) { self::p404(); return null; } - $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates'); - $_ctx = & $GLOBALS['_ctx']; - $core = $GLOBALS['core']; + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates'); header('Content-Type: text/html; charset=UTF-8'); http::head(404, 'Not Found'); - $core->url->type = '404'; - $_ctx->current_tpl = 'kutrl404.html'; - $_ctx->content_type = 'text/html'; + dcCore::app()->url->type = '404'; + dcCore::app()->ctx->current_tpl = 'kutrl404.html'; + dcCore::app()->ctx->content_type = 'text/html'; - echo $core->tpl->getData($_ctx->current_tpl); + echo dcCore::app()->tpl->getData(dcCore::app()->ctx->current_tpl); # --BEHAVIOR-- publicAfterDocument - $core->callBehavior('publicAfterDocument', $core); + dcCore::app()->callBehavior('publicAfterDocumentV2'); exit; } } @@ -259,11 +253,11 @@ class pubKutrl 'EntryURL', 'EntryCategoryURL', 'CommentAuthorURL', - 'CommentPostURL' + 'CommentPostURL', ]; # Disable URL shoretning on filtered tag - public static function templateBeforeValue($core, $tag, $attr) + public static function templateBeforeValue($tag, $attr) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) { return ''; @@ -273,7 +267,7 @@ class pubKutrl } # Re unable it after tag - public static function templateAfterValue($core, $tag, $attr) + public static function templateAfterValue($tag, $attr) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) { return ''; @@ -283,7 +277,7 @@ class pubKutrl } # Replace long urls on the fly (on filter) for default tags - public static function publicBeforeContentFilter($core, $tag, $args) + public static function publicBeforeContentFilter($tag, $args) { # Unknow tag if (!in_array($tag, pubKutrl::$know_tags)) { @@ -292,53 +286,50 @@ class pubKutrl # URL shortening is disabled by tag attribute if (empty($GLOBALS['disable_kutrl'])) { # kUtRL is not activated - if (!$core->blog->settings->kUtRL->kutrl_active - || !$core->blog->settings->kUtRL->kutrl_tpl_active + if (!dcCore::app()->blog->settings->kUtRL->kutrl_active + || !dcCore::app()->blog->settings->kUtRL->kutrl_tpl_active ) { return null; } - global $_ctx; - # Oups - if (!$_ctx->exists('kutrl')) { + if (!dcCore::app()->ctx->exists('kutrl')) { return null; } # Existing - if (false !== ($kutrl_rs = $_ctx->kutrl->isKnowUrl($args[0]))) { - $args[0] = $_ctx->kutrl->url_base . $kutrl_rs->hash; + if (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->isKnowUrl($args[0]))) { + $args[0] = dcCore::app()->ctx->kutrl->url_base . $kutrl_rs->hash; # New - } elseif (false !== ($kutrl_rs = $_ctx->kutrl->hash($args[0]))) { - $args[0] = $_ctx->kutrl->url_base . $kutrl_rs->hash; + } elseif (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->hash($args[0]))) { + $args[0] = dcCore::app()->ctx->kutrl->url_base . $kutrl_rs->hash; # ex: Send new url to messengers if (!empty($kutrl_rs)) { - $core->callBehavior('publicAfterKutrlCreate', $core, $kutrl_rs, __('New public short URL')); + dcCore::app()->callBehavior('publicAfterKutrlCreate', $kutrl_rs, __('New public short URL')); } } } } - public static function publicBeforeDocument($core) + public static function publicBeforeDocument() { - global $_ctx; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; # Passive : all kutrl tag return long url - $_ctx->kutrl_passive = (bool) $s->kutrl_tpl_passive; + dcCore::app()->ctx->kutrl_passive = (bool) $s->kutrl_tpl_passive; if (!$s->kutrl_active || !$s->kutrl_tpl_service) { return null; } - if (null === ($kut = kutrl::quickPlace('tpl'))) { + if (null === ($kut = kUtRL::quickPlace('tpl'))) { return null; } - $_ctx->kutrl = $kut; + dcCore::app()->ctx->kutrl = $kut; } public static function publicHeadContent($core) { - $css = $core->blog->settings->kUtRL->kutrl_srv_local_css; + $css = dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_css; if ($css) { echo "\n \n" . @@ -353,9 +344,9 @@ class tplKutrl { public static function pageURL($attr) { - $f = $GLOBALS['core']->tpl->getFilters($attr); + $f = dcCore::app()->tpl->getFilters($attr); - return 'blog->url.$core->url->getBase("kutrl")') . '; ?>'; + return 'blog->url.dcCore::app()->url->getBase("kutrl")') . '; ?>'; } public static function pageIf($attr, $content) @@ -364,7 +355,7 @@ class tplKutrl if (isset($attr['is_active'])) { $sign = (bool) $attr['is_active'] ? '' : '!'; - $if[] = $sign . '$core->blog->settings->kUtRL->kutrl_srv_local_public'; + $if[] = $sign . 'dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_public'; } if (empty($if)) { return $content; @@ -382,7 +373,7 @@ class tplKutrl if (isset($attr['has_message'])) { $sign = (bool) $attr['has_message'] ? '!' : '='; - $if[] = '"" ' . $sign . '= $_ctx->kutrl_msg'; + $if[] = '"" ' . $sign . '= dcCore::app()->ctx->kutrl_msg'; } if (empty($if)) { return $content; @@ -396,19 +387,19 @@ class tplKutrl public static function pageMsg($attr) { - return 'kutrl_msg; ?>'; + return 'ctx->kutrl_msg; ?>'; } public static function humanField($attr) { - return "kutrl_hmf); ?>"; + return "ctx->kutrl_hmf); ?>"; } public static function humanFieldProtect($attr) { return - '' . - 'formNonce(); ?>'; + '' . + 'formNonce(); ?>'; } public static function AttachmentKutrlIf($attr, $content) @@ -423,52 +414,52 @@ class tplKutrl public static function MediaKutrlIf($attr, $content) { - return self::genericKutrlIf('$_ctx->file_url', $attr, $content); + return self::genericKutrlIf('dcCore::app()->ctx->file_url', $attr, $content); } public static function MediaKutrl($attr) { - return self::genericKutrl('$_ctx->file_url', $attr); + return self::genericKutrl('dcCore::app()->ctx->file_url', $attr); } public static function EntryAuthorKutrlIf($attr, $content) { - return self::genericKutrlIf('$_ctx->posts->user_url', $attr, $content); + return self::genericKutrlIf('dcCore::app()->ctx->posts->user_url', $attr, $content); } public static function EntryAuthorKutrl($attr) { - return self::genericKutrl('$_ctx->posts->user_url', $attr); + return self::genericKutrl('dcCore::app()->ctx->posts->user_url', $attr); } public static function EntryKutrlIf($attr, $content) { - return self::genericKutrlIf('$_ctx->posts->getURL()', $attr, $content); + return self::genericKutrlIf('dcCore::app()->ctx->posts->getURL()', $attr, $content); } public static function EntryKutrl($attr) { - return self::genericKutrl('$_ctx->posts->getURL()', $attr); + return self::genericKutrl('dcCore::app()->ctx->posts->getURL()', $attr); } public static function CommentAuthorKutrlIf($attr, $content) { - return self::genericKutrlIf('$_ctx->comments->getAuthorURL()', $attr, $content); + return self::genericKutrlIf('dcCore::app()->ctx->comments->getAuthorURL()', $attr, $content); } public static function CommentAuthorKutrl($attr) { - return self::genericKutrl('$_ctx->comments->getAuthorURL()', $attr); + return self::genericKutrl('dcCore::app()->ctx->comments->getAuthorURL()', $attr); } public static function CommentPostKutrlIf($attr, $content) { - return self::genericKutrlIf('$_ctx->comments->getPostURL()', $attr, $content); + return self::genericKutrlIf('dcCore::app()->ctx->comments->getPostURL()', $attr, $content); } public static function CommentPostKutrl($attr) { - return self::genericKutrl('$_ctx->comments->getPostURL()', $attr); + return self::genericKutrl('dcCore::app()->ctx->comments->getPostURL()', $attr); } protected static function genericKutrlIf($str, $attr, $content) @@ -477,15 +468,15 @@ class tplKutrl if (isset($attr['is_active'])) { $sign = (bool) $attr['is_active'] ? '' : '!'; - $if[] = $sign . '$_ctx->exists("kutrl")'; + $if[] = $sign . 'dcCore::app()->ctx->exists("kutrl")'; } if (isset($attr['passive_mode'])) { $sign = (bool) $attr['passive_mode'] ? '' : '!'; - $if[] = $sign . '$_ctx->kutrl_passive'; + $if[] = $sign . 'dcCore::app()->ctx->kutrl_passive'; } if (isset($attr['has_kutrl'])) { $sign = (bool) $attr['has_kutrl'] ? '!' : '='; - $if[] = '($_ctx->exists("kutrl") && false ' . $sign . '== $_ctx->kutrl->select(' . $str . ',null,null,"kutrl"))'; + $if[] = '(dcCore::app()->ctx->exists("kutrl") && false ' . $sign . '== dcCore::app()->ctx->kutrl->select(' . $str . ',null,null,"kutrl"))'; } if (empty($if)) { return $content; @@ -499,32 +490,32 @@ class tplKutrl protected static function genericKutrl($str, $attr) { - $f = $GLOBALS['core']->tpl->getFilters($attr); + $f = dcCore::app()->tpl->getFilters($attr); return "preview) { \n" . + "if (dcCore::app()->ctx->preview) { \n" . ' echo ' . sprintf($f, $str) . '; ' . "} else { \n" . # Disable - "if (!\$_ctx->exists('kutrl')) { \n" . + "if (!dcCore::app()->ctx->exists('kutrl')) { \n" . # Passive mode - ' if ($_ctx->kutrl_passive) { ' . + ' if (dcCore::app()->ctx->kutrl_passive) { ' . ' echo ' . sprintf($f, $str) . '; ' . " } \n" . "} else { \n" . # Existing - ' if (false !== ($kutrl_rs = $_ctx->kutrl->isKnowUrl(' . $str . '))) { ' . - ' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . + ' if (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->isKnowUrl(' . $str . '))) { ' . + ' echo ' . sprintf($f, 'dcCore::app()->ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . " } \n" . # New - ' elseif (false !== ($kutrl_rs = $_ctx->kutrl->hash(' . $str . '))) { ' . - ' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . + ' elseif (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->hash(' . $str . '))) { ' . + ' echo ' . sprintf($f, 'dcCore::app()->ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . # ex: Send new url to messengers ' if (!empty($kutrl_rs)) { ' . - " \$core->callBehavior('publicAfterKutrlCreate',\$core,\$kutrl_rs,__('New public short URL')); " . + " dcCore::app()->callBehavior('publicAfterKutrlCreate',\$kutrl_rs,__('New public short URL')); " . " } \n" . " } \n" . diff --git a/_widgets.php b/_widgets.php index 50f7859..2daab61 100644 --- a/_widgets.php +++ b/_widgets.php @@ -14,8 +14,8 @@ if (!defined('DC_RC_PATH')) { return null; } -$core->addBehavior('initWidgets', ['widgetKutrl', 'adminShorten']); -$core->addBehavior('initWidgets', ['widgetKutrl', 'adminRank']); +dcCore::app()->addBehavior('initWidgets', ['widgetKutrl', 'adminShorten']); +dcCore::app()->addBehavior('initWidgets', ['widgetKutrl', 'adminRank']); class widgetKutrl { @@ -64,7 +64,7 @@ class widgetKutrl __('All') => '-', __('Mini URL') => 'localnormal', __('Custom URL') => 'localcustom', - __('Semi-custom') => 'localmix' + __('Semi-custom') => 'localmix', ] ) ->setting( @@ -81,7 +81,7 @@ class widgetKutrl [ __('Date') => 'kut_dt', __('Rank') => 'kut_counter', - __('Hash') => 'kut_hash' + __('Hash') => 'kut_hash', ] ) ->setting( @@ -91,7 +91,7 @@ class widgetKutrl 'combo', [ __('Ascending') => 'asc', - __('Descending') => 'desc' + __('Descending') => 'desc', ] ) ->setting( @@ -114,13 +114,12 @@ class widgetKutrl public static function publicShorten($w) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (!$s->kutrl_active || !$s->kutrl_srv_local_public - || ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 2 && $core->url->isHome($core->url->type)) - || $core->url->type == 'kutrl') { + || ($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)) || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type)) + || dcCore::app()->url->type == 'kutrl') { return null; } @@ -133,7 +132,7 @@ class widgetKutrl '', ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . '
' . + dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '">' . '

' . '

' . form::hidden('hmfp', $hmfp) . - $core->formNonce() . + dcCore::app()->formNonce() . '

' . '
' ); @@ -152,23 +151,22 @@ class widgetKutrl public static function publicRank($w) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (!$s->kutrl_active - || ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 2 && $core->url->isHome($core->url->type))) { + || ($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)) || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))) { return null; } $type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ? "AND kut_type ='" . $w->type . "' " : - 'AND kut_type ' . $core->con->in(['localnormal', 'localmix', 'localcustom']) . ' '; + 'AND kut_type ' . dcCore::app()->con->in(['localnormal', 'localmix', 'localcustom']) . ' '; $hide = (bool) $w->hideempty ? 'AND kut_counter > 0 ' : ''; $more = ''; if ($w->type == 'localmix' && '' != $w->mixprefix) { - $more = "AND kut_hash LIKE '" . $core->con->escape($w->mixprefix) . "%' "; + $more = "AND kut_hash LIKE '" . dcCore::app()->con->escape($w->mixprefix) . "%' "; } $order = ($w->sortby && in_array($w->sortby, ['kut_dt', 'kut_counter', 'kut_hash'])) ? @@ -176,12 +174,12 @@ class widgetKutrl $order .= $w->sort == 'desc' ? ' DESC' : ' ASC'; - $limit = $core->con->limit(abs((int) $w->limit)); + $limit = dcCore::app()->con->limit(abs((int) $w->limit)); - $rs = $core->con->select( + $rs = dcCore::app()->con->select( 'SELECT kut_counter, kut_hash ' . - 'FROM ' . $core->prefix . 'kutrl ' . - "WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . + 'FROM ' . dcCore::app()->prefix . 'kutrl ' . + "WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " . "AND kut_service = 'local' " . $type . $hide . $more . 'ORDER BY ' . $order . $limit ); @@ -197,7 +195,7 @@ class widgetKutrl $rank = '' . $i . ''; $hash = $rs->kut_hash; - $url = $core->blog->url . $core->url->getBase('kutrl') . '/' . $hash; + $url = dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/' . $hash; $cut_len = - abs((int) $w->urllen); if (strlen($url) > $cut_len) { @@ -217,7 +215,7 @@ class widgetKutrl } $content .= '
  • ' . str_replace( ['%rank%', '%hash%', '%url%', '%count%', '%counttext%'], diff --git a/inc/class.kutrl.php b/inc/class.kutrl.php index c5435d4..d5e7aee 100644 --- a/inc/class.kutrl.php +++ b/inc/class.kutrl.php @@ -18,9 +18,9 @@ if (!defined('DC_RC_PATH')) { class kUtRL { # Load services list from behavior - public static function getServices(dcCore $core) + public static function getServices() { - $list = $core->getBehaviors('kutrlService'); + $list = dcCore::app()->getBehaviors('kutrlService'); if (empty($list)) { return []; @@ -28,8 +28,8 @@ class kUtRL $services = []; foreach ($list as $k => $callback) { try { - list($service_id, $service_class) = call_user_func($callback); - $services[(string) $service_id] = (string) $service_class; + [$service_id, $service_class] = call_user_func($callback); + $services[(string) $service_id] = (string) $service_class; } catch (Exception $e) { } } @@ -41,15 +41,13 @@ class kUtRL # Return null on error else service on success public static function quickService($id = '') { - global $core; - try { if (empty($id)) { return null; } - $services = self::getServices($core); + $services = self::getServices(); if (isset($services[$id])) { - return new $services[$id]($core); + return new $services[$id](); } } catch (Exception $e) { } @@ -61,13 +59,11 @@ class kUtRL # Return null on error else service on success public static function quickPlace($place = 'plugin') { - global $core; - try { if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) { return null; } - $id = $core->blog->settings->kUtRL->get('kutrl_' . $place . '_service'); + $id = dcCore::app()->blog->settings->kUtRL->get('kutrl_' . $place . '_service'); if (!empty($id)) { return self::quickService($id); } @@ -81,8 +77,6 @@ class kUtRL # return long url on error else short url on success public static function quickReduce($url, $custom = null, $place = 'plugin') { - global $core; - try { $srv = self::quickPlace($place); if (empty($srv)) { diff --git a/inc/lib.kutrl.activityreport.php b/inc/lib.kutrl.activityreport.php index f2f5729..d637967 100644 --- a/inc/lib.kutrl.activityreport.php +++ b/inc/lib.kutrl.activityreport.php @@ -16,10 +16,10 @@ if (!defined('DC_RC_PATH')) { return null; } -$core->activityReport->addGroup('kutrl', __('Plugin kUtRL')); +dcCore::app()->activityReport->addGroup('kutrl', __('Plugin kUtRL')); # from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php -$core->activityReport->addAction( +dcCore::app()->activityReport->addAction( 'kutrl', 'create', __('Short link creation'), @@ -34,6 +34,6 @@ class kutrlActivityReportBehaviors { $logs = [$rs->type,$rs->hash]; - $GLOBALS['core']->activityReport->addLog('kutrl', 'create', $logs); + dcCore::app()->activityReport->addLog('kutrl', 'create', $logs); } } diff --git a/inc/lib.kutrl.log.php b/inc/lib.kutrl.log.php index 4364c39..9db3030 100644 --- a/inc/lib.kutrl.log.php +++ b/inc/lib.kutrl.log.php @@ -14,17 +14,15 @@ class kutrlLog { - public $core; public $table; public $blog; public $con; - public function __construct(dcCore $core) + public function __construct() { - $this->core = $core; - $this->table = $core->prefix . 'kutrl'; - $this->blog = $core->con->escape($core->blog->id); - $this->con = $core->con; + $this->table = dcCore::app()->prefix . 'kutrl'; + $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); + $this->con = dcCore::app()->con; } public function nextId() @@ -58,7 +56,7 @@ class kutrlLog 'hash' => $hash, 'type' => $type, 'service' => $service, - 'counter ' => 0 + 'counter ' => 0, ]; } catch (Exception $e) { $this->con->unlock(); diff --git a/inc/lib.kutrl.lst.php b/inc/lib.kutrl.lst.php index fc02c6a..46ffe0f 100644 --- a/inc/lib.kutrl.lst.php +++ b/inc/lib.kutrl.lst.php @@ -12,15 +12,13 @@ */ class kutrlLinkslist { - protected $core; protected $rs; protected $rs_count; protected $html_prev; protected $html_next; - public function __construct(dcCore $core, $rs, $rs_count) + public function __construct($rs, $rs_count) { - $this->core = &$core; $this->rs = &$rs; $this->rs_count = $rs_count; $this->html_prev = __('« prev.'); @@ -29,7 +27,7 @@ class kutrlLinkslist public function userColumns($type, $cols) { - $cols_user = @$this->core->auth->user_prefs->interface->cols; + $cols_user = @dcCore::app()->auth->user_prefs->interface->cols; if (is_array($cols_user) || $cols_user instanceof ArrayObject) { if (isset($cols_user[$type])) { foreach ($cols_user[$type] as $cn => $cd) { @@ -62,7 +60,7 @@ class kutrlLinkslist 'kut_url' => '' . __('Link') . '', 'kut_hash' => '' . __('Hash') . '', 'kut_dt' => '' . __('Date') . '', - 'kut_service' => '' . __('Service') . '' + 'kut_service' => '' . __('Service') . '', ]; $cols = new ArrayObject($cols); $this->userColumns('kUtRL', $cols); @@ -101,7 +99,7 @@ class kutrlLinkslist $type = $this->rs->kut_type; $hash = $this->rs->kut_hash; - if (null !== ($o = kutrl::quickService($type))) { + if (null !== ($o = kUtRL::quickService($type))) { $type = '' . $o->name . ''; $hash = '' . $hash . ''; } @@ -117,11 +115,11 @@ class kutrlLinkslist $hash . '', 'kut_dt' => '' . - dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) . + dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, dcCore::app()->auth->getInfo('user_tz')) . '', 'kut_service' => '' . $type . - '' + '', ]; $cols = new ArrayObject($cols); diff --git a/inc/lib.kutrl.srv.php b/inc/lib.kutrl.srv.php index 880beec..60017ce 100644 --- a/inc/lib.kutrl.srv.php +++ b/inc/lib.kutrl.srv.php @@ -14,20 +14,18 @@ # A service class must extends this one class kutrlService { - public $core; public $error; public $settings; public $log; protected $config = []; - public function __construct($core) + public function __construct() { - $this->core = $core; - $this->settings = $core->blog->settings->kUtRL; - $this->log = new kutrlLog($core); + $this->settings = dcCore::app()->blog->settings->kUtRL; + $this->log = new kutrlLog(); $this->error = new dcError(); - $this->error->setHTMLFormat('%s', "%s\n"); + //$this->error->setHTMLFormat('%s', "%s\n"); $this->init(); @@ -49,7 +47,7 @@ class kutrlService 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', 'url_api' => '', 'url_base' => '', - 'url_min_len' => 0 + 'url_min_len' => 0, ], $this->config ); @@ -130,7 +128,7 @@ class kutrlService # Test if an url is from current blog public function isBlogUrl($url) { - $base = $this->core->blog->url; + $base = dcCore::app()->blog->url; $url = substr($url, 0, strlen($base)); return $url == $base; @@ -151,7 +149,7 @@ class kutrlService # Create hash from url public function hash($url, $hash = null) { - $url = trim($this->core->con->escape($url)); + $url = trim(dcCore::app()->con->escape($url)); if ('undefined' === $this->id) { return false; } @@ -176,10 +174,10 @@ class kutrlService } $this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl'); - $this->core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); # --BEHAVIOR-- kutrlAfterCreateShortUrl - $this->core->callBehavior('kutrlAfterCreateShortUrl', $rs); + dcCore::app()->callBehavior('kutrlAfterCreateShortUrl', $rs); } return $rs; diff --git a/inc/lib.wiki.kutrl.php b/inc/lib.wiki.kutrl.php index 9a960ac..d697cba 100644 --- a/inc/lib.wiki.kutrl.php +++ b/inc/lib.wiki.kutrl.php @@ -20,17 +20,16 @@ class kutrlWiki { public static function coreInitWiki($wiki2xhtml) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; # Do nothing on comment preview and post preview if (!empty($_POST['preview']) - || !empty($GLOBALS['_ctx']) && $GLOBALS['_ctx']->preview + || isset(dcCore::app()->ctx) && dcCore::app()->ctx->preview || !$s->kutrl_active ) { return null; } - if (null === ($kut = kutrl::quickPlace('wiki'))) { + if (null === ($kut = kUtRL::quickPlace('wiki'))) { return null; } foreach ($kut->allow_protocols as $protocol) { @@ -43,13 +42,12 @@ class kutrlWiki public static function transform($url, $content) { - global $core; - $s = $core->blog->settings->kUtRL; + $s = dcCore::app()->blog->settings->kUtRL; if (!$s->kutrl_active) { return null; } - if (null === ($kut = kutrl::quickPlace('wiki'))) { + if (null === ($kut = kUtRL::quickPlace('wiki'))) { return []; } # Test if long url exists @@ -72,7 +70,7 @@ class kutrlWiki # ex: Send new url to messengers if (!empty($rs)) { - $core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL')); + dcCore::app()->callBehavior('wikiAfterKutrlCreate', $rs, __('New short URL')); } return $res; diff --git a/inc/patch.dcminiurl.php b/inc/patch.dcminiurl.php index 3708dc9..f552f7f 100644 --- a/inc/patch.dcminiurl.php +++ b/inc/patch.dcminiurl.php @@ -17,28 +17,26 @@ if (!defined('DC_CONTEXT_ADMIN')) { return; } -$miniurl_patch = new dcMiniUrl2kUtRL($core); +$miniurl_patch = new dcMiniUrl2kUtRL(); if ($miniurl_patch->parseRecords()) { try { - $core->plugins->deactivateModule('dcMiniUrl'); + dcCore::app()->plugins->deactivateModule('dcMiniUrl'); } catch (Exception $e) { - //$core->error->add($e->getMessage()); + //dcCore::app()->error->add($e->getMessage()); } } class dcMiniUrl2kUtRL { - public $core; - + public $con; public $k_tb; public $m_tb; - public function __construct($core) + public function __construct() { - $this->core = $core; - $this->con = $core->con; - $this->k_tb = $core->prefix . 'kutrl'; - $this->m_tb = $core->prefix . 'miniurl'; + $this->con = dcCore::app()->con; + $this->k_tb = dcCore::app()->prefix . 'kutrl'; + $this->m_tb = dcCore::app()->prefix . 'miniurl'; } public function parseRecords() diff --git a/inc/services/class.bilbolinks.service.php b/inc/services/class.bilbolinks.service.php index e264283..03f8d91 100644 --- a/inc/services/class.bilbolinks.service.php +++ b/inc/services/class.bilbolinks.service.php @@ -19,7 +19,7 @@ class bilbolinksKutrlService extends kutrlService protected $config = [ 'id' => 'bilbolinks', 'name' => 'BilboLinks', - 'home' => 'http://www.tux-planet.fr/bilbobox/' + 'home' => 'http://www.tux-planet.fr/bilbobox/', ]; protected function init() diff --git a/inc/services/class.bitly.service.php b/inc/services/class.bitly.service.php index a3dfdef..0c958b3 100644 --- a/inc/services/class.bitly.service.php +++ b/inc/services/class.bitly.service.php @@ -29,7 +29,7 @@ class bitlyKutrlService extends kutrlService ]; private $args = [ - 'apiKey' => '' + 'apiKey' => '', ]; protected function init() diff --git a/inc/services/class.custom.service.php b/inc/services/class.custom.service.php index 615dd15..6571762 100644 --- a/inc/services/class.custom.service.php +++ b/inc/services/class.custom.service.php @@ -18,12 +18,12 @@ class customKutrlService extends kutrlService { protected $config = [ 'id' => 'custom', - 'name' => 'Custom' + 'name' => 'Custom', ]; protected function init() { - $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); + $config = unserialize(base64_decode((string) $this->settings->kutrl_srv_custom)); if (!is_array($config)) { $config = []; } @@ -42,7 +42,7 @@ class customKutrlService extends kutrlService 'url_api' => $_POST['kutrl_srv_custom_url_api'], 'url_base' => $_POST['kutrl_srv_custom_url_base'], 'url_param' => $_POST['kutrl_srv_custom_url_param'], - 'url_encode' => !empty($_POST['kutrl_srv_custom_url_encode']) + 'url_encode' => !empty($_POST['kutrl_srv_custom_url_encode']), ]; $this->settings->put('kutrl_srv_custom', base64_encode(serialize($config))); } @@ -53,9 +53,9 @@ class customKutrlService extends kutrlService 'url_api' => '', 'url_base' => '', 'url_param' => '', - 'url_encode' => true + 'url_encode' => true, ]; - $config = unserialize(base64_decode($this->settings->kutrl_srv_custom)); + $config = unserialize(base64_decode((string) $this->settings->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 ffce046..ce330c9 100644 --- a/inc/services/class.default.service.php +++ b/inc/services/class.default.service.php @@ -33,7 +33,7 @@ class defaultKutrlService extends kutrlService 'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2, 'url_param' => SHORTEN_SERVICE_PARAM, - 'url_encode' => SHORTEN_SERVICE_ENCODE + 'url_encode' => SHORTEN_SERVICE_ENCODE, ]; } diff --git a/inc/services/class.googl.service.php b/inc/services/class.googl.service.php index aa0ce5e..eb34db5 100644 --- a/inc/services/class.googl.service.php +++ b/inc/services/class.googl.service.php @@ -23,7 +23,7 @@ class googlKutrlService extends kutrlService private $url_api = 'https://www.googleapis.com/urlshortener/v1/url'; private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; private $args = [ - 'key' => '' + 'key' => '', ]; private $headers = ['Content-Type: application/json']; diff --git a/inc/services/class.isgd.service.php b/inc/services/class.isgd.service.php index e5cac6b..bc5f637 100644 --- a/inc/services/class.isgd.service.php +++ b/inc/services/class.isgd.service.php @@ -23,7 +23,7 @@ class isgdKutrlService extends kutrlService 'url_api' => 'http://is.gd/api.php', 'url_base' => 'http://is.gd/', - 'url_min_length' => 25 + 'url_min_length' => 25, ]; public function testService() diff --git a/inc/services/class.local.service.php b/inc/services/class.local.service.php index 9d88db5..f332df8 100644 --- a/inc/services/class.local.service.php +++ b/inc/services/class.local.service.php @@ -21,7 +21,7 @@ class localKutrlService extends kutrlService 'name' => 'kUtRL', 'home' => 'https://github.com/JcDenis/kUtRL', - 'allow_custom_hash' => true + 'allow_custom_hash' => true, ]; protected function init() @@ -29,7 +29,7 @@ class localKutrlService extends kutrlService $protocols = (string) $this->settings->kutrl_srv_local_protocols; $this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols); - $this->config['url_base'] = $this->core->blog->url . $this->core->url->getBase('kutrl') . '/'; + $this->config['url_base'] = dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/'; $this->config['url_min_len'] = strlen($this->url_base) + 2; } @@ -62,7 +62,7 @@ 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->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".') . '

    ' . @@ -221,7 +221,6 @@ class localKutrlService extends kutrlService return false; } if (!$rs->url) { //previously removed url - return false; } $this->log->counter($rs->id, 'up'); diff --git a/inc/services/class.shortto.service.php b/inc/services/class.shortto.service.php index 6686054..7f91268 100644 --- a/inc/services/class.shortto.service.php +++ b/inc/services/class.shortto.service.php @@ -23,7 +23,7 @@ class shorttoKutrlService extends kutrlService 'url_api' => 'http://short.to/s.txt', 'url_base' => 'http://short.to/', - 'url_min_len' => 25 + 'url_min_len' => 25, ]; public function testService() diff --git a/inc/services/class.supr.service.php b/inc/services/class.supr.service.php index f45d099..f8b1bdb 100644 --- a/inc/services/class.supr.service.php +++ b/inc/services/class.supr.service.php @@ -23,14 +23,14 @@ class suprKutrlService extends kutrlService 'url_api' => 'http://su.pr/api/', 'url_base' => 'http://su.pr/', - 'url_min_len' => 23 + 'url_min_len' => 23, ]; private $args = [ 'version' => '1.0', 'format' => 'xml', 'login' => '', - 'apiKey' => '' + 'apiKey' => '', ]; protected function init() diff --git a/inc/services/class.trim.service.php b/inc/services/class.trim.service.php index 5284821..09e1a9d 100644 --- a/inc/services/class.trim.service.php +++ b/inc/services/class.trim.service.php @@ -23,12 +23,12 @@ class trimKutrlService extends kutrlService 'url_api' => 'http://api.tr.im/v1/', 'url_base' => 'http://tr.im/', - 'url_min_len' => 25 + 'url_min_len' => 25, ]; private $args = [ 'username' => '', - 'password' => '' + 'password' => '', ]; private $api_rate_time = 0; diff --git a/inc/services/class.yourls.service.php b/inc/services/class.yourls.service.php index 7c4008d..b14eae2 100644 --- a/inc/services/class.yourls.service.php +++ b/inc/services/class.yourls.service.php @@ -19,14 +19,14 @@ class yourlsKutrlService extends kutrlService protected $config = [ 'id' => 'yourls', 'name' => 'YOURLS', - 'home' => 'http://yourls.org' + 'home' => 'http://yourls.org', ]; private $args = [ 'username' => '', 'password' => '', 'format' => 'xml', - 'action' => 'shorturl' + 'action' => 'shorturl', ]; protected function init() diff --git a/index.php b/index.php index 18d3086..4f128e3 100644 --- a/index.php +++ b/index.php @@ -15,7 +15,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { } # Check user perms -dcPage::check('admin'); +dcPage::check(dcAuth::PERMISSION_ADMIN); $header = ''; $part = $_REQUEST['part'] ?? 'links'; @@ -23,14 +23,14 @@ $action = $_POST['action'] ?? ''; # link creation if ($part == 'link') { - $kut = kutrl::quickPlace('admin'); + $kut = kUtRL::quickPlace('admin'); if (!empty($_POST['save'])) { try { if (null === $kut) { throw new Exception('Unknow service'); } - $url = trim($core->con->escape($_POST['str'])); + $url = trim(dcCore::app()->con->escape($_POST['str'])); $hash = empty($_POST['custom']) ? null : $_POST['custom']; if (empty($url)) { @@ -64,7 +64,7 @@ if ($part == 'link') { $url = $rs->url; $new_url = $kut->url_base . $rs->hash; - dcPage::addSuccessNotice(sprintf( + dcAdminNotices::addSuccessNotice(sprintf( __('Short link for %s is %s'), '' . html::escapeHTML($url) . '', '' . $new_url . '' @@ -80,7 +80,7 @@ if ($part == 'link') { $url = $rs->url; $new_url = $kut->url_base . $rs->hash; - dcPage::addSuccessNotice(sprintf( + dcAdminNotices::addSuccessNotice(sprintf( __('Short link for %s is %s'), '' . html::escapeHTML($url) . '', '' . $new_url . '' @@ -88,28 +88,28 @@ if ($part == 'link') { # ex: Send new url to messengers if (!empty($rs)) { - $core->callBehavior('adminAfterKutrlCreate', $core, $rs, __('New short URL')); + dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, __('New short URL')); } } } } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } - # links +# links } else { $services_combo = []; - foreach (kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); + foreach (kUtRL::getServices() as $service_id => $service) { + $o = new $service(); $services_combo[__($o->name)] = $o->id; } $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); $lst_services_combo = array_merge(['-' => ''], $services_combo); - $log = new kutrlLog($core); + $log = new kutrlLog(); - $kUtRL_filter = new adminGenericFilter($core, 'kUtRL'); + $kUtRL_filter = new adminGenericFilterV2('kUtRL'); $kUtRL_filter->add('part', 'links'); $kUtRL_filter->add(dcAdminFilters::getPageFilter()); $kUtRL_filter->add(dcAdminFilters::getSelectFilter( @@ -124,12 +124,12 @@ if ($part == 'link') { try { $list_all = $log->getLogs($params); $list_counter = $log->getLogs($params, true)->f(0); - $list_current = new kutrlLinksList($core, $list_all, $list_counter); + $list_current = new kutrlLinkslist($list_all, $list_counter); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } - $header = $kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) . + $header = $kUtRL_filter->js(dcCore::app()->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) . dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); if (!empty($_POST['deletelinks'])) { @@ -139,20 +139,20 @@ if ($part == 'link') { if ($rs->isEmpty()) { continue; } - if (null === ($o = kutrl::quickService($rs->kut_type))) { + if (null === ($o = kUtRL::quickService($rs->kut_type))) { continue; } $o->remove($rs->kut_url); } - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Links successfully deleted') ); - $core->adminurl->redirect('admin.plugin.kUtRL', $kUtRL_filter->values()); + dcCore::app()->adminurl->redirect('admin.plugin.kUtRL', $kUtRL_filter->values()); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } } @@ -168,8 +168,8 @@ if ($part == 'link') { echo dcPage::breadcrumb([ __('Plugins') => '', - __('Links shortener') => $core->adminurl->get('admin.plugin.kUtRL'), - __('New link') => '' + __('Links shortener') => dcCore::app()->adminurl->get('admin.plugin.kUtRL'), + __('New link') => '', ]) . dcPage::notices(); @@ -179,7 +179,7 @@ if ($part == 'link') { echo '

    ' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '

    -
    '; @@ -208,12 +208,12 @@ if ($part == 'link') { echo dcPage::breadcrumb([ __('Plugins') => '', - __('Links shortener') => '' + __('Links shortener') => '', ]) . dcPage::notices() . '

    ' . __('New Link') . '

    '; $kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links')); @@ -221,7 +221,7 @@ if ($part == 'link') { $list_current->display( $kUtRL_filter->value('page'), $kUtRL_filter->nb, - '
    + ' %s @@ -231,8 +231,8 @@ if ($part == 'link') {
  • ' . - $core->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . - $core->formNonce() . ' + dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . + dcCore::app()->formNonce() . '

    ', diff --git a/locales/en/resources.php b/locales/en/resources.php index ff716a3..d1eb869 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) { return; } -$__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html'; +dcCore::app()->resources['help']['kUtRL'] = __DIR__ . '/help/help.html'; diff --git a/locales/fr/resources.php b/locales/fr/resources.php index ff716a3..d1eb869 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) { return; } -$__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html'; +dcCore::app()->resources['help']['kUtRL'] = __DIR__ . '/help/help.html';