prepare to DC 2.24

master
Jean-Christian Paul Denis 2022-11-20 17:15:36 +01:00
parent 6a1d365762
commit 3a9e90ac9f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
28 changed files with 403 additions and 405 deletions

View File

@ -14,39 +14,38 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; 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 # Plugin menu
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Links shortener'), __('Links shortener'),
$core->adminurl->get('admin.plugin.kUtRL'), dcCore::app()->adminurl->get('admin.plugin.kUtRL'),
dcPage::getPF('kUtRL/icon.png'), dcPage::getPF('kUtRL/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('admin', $core->blog->id) dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)
); );
# Admin behaviors # Admin behaviors
if ($core->blog->settings->kUtRL->kutrl_active) { if (dcCore::app()->blog->settings->kUtRL->kutrl_active) {
$core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']); dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminKutrl', 'antispamDashboardFavorites']);
$core->addBehavior('adminColumnsLists', ['adminKutrl', 'adminColumnsLists']); dcCore::app()->addBehavior('adminColumnsListsV2', ['adminKutrl', 'adminColumnsLists']);
$core->addBehavior('adminFiltersLists', ['adminKutrl', 'adminFiltersLists']); dcCore::app()->addBehavior('adminFiltersListsV2', ['adminKutrl', 'adminFiltersLists']);
$core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); dcCore::app()->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']);
$core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']); dcCore::app()->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']);
$core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url
$core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostCreate']); // create new short url dcCore::app()->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostCreate']); // create new short url
$core->addBehavior('adminAfterPostCreate', ['adminKutrl', 'adminAfterPostCreate']); dcCore::app()->addBehavior('adminAfterPostCreate', ['adminKutrl', 'adminAfterPostCreate']);
$core->addBehavior('adminBeforePostDelete', ['adminKutrl', 'adminBeforePostDelete']); dcCore::app()->addBehavior('adminBeforePostDelete', ['adminKutrl', 'adminBeforePostDelete']);
$core->addBehavior('adminPostsActionsCombo', ['adminKutrl', 'adminPostsActionsCombo']); dcCore::app()->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']);
$core->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']);
} }
$core->addBehavior('exportFull', ['backupKutrl', 'exportFull']); dcCore::app()->addBehavior('exportFullV2', ['backupKutrl', 'exportFull']);
$core->addBehavior('exportSingle', ['backupKutrl', 'exportSingle']); dcCore::app()->addBehavior('exportSingleV2', ['backupKutrl', 'exportSingle']);
$core->addBehavior('importInit', ['backupKutrl', 'importInit']); dcCore::app()->addBehavior('importInitV2', ['backupKutrl', 'importInit']);
$core->addBehavior('importSingle', ['backupKutrl', 'importSingle']); dcCore::app()->addBehavior('importSingleV2', ['backupKutrl', 'importSingle']);
$core->addBehavior('importFull', ['backupKutrl', 'importFull']); dcCore::app()->addBehavior('importFullV2', ['backupKutrl', 'importFull']);
# Admin behaviors class # Admin behaviors class
class adminKutrl class adminKutrl
@ -57,44 +56,44 @@ class adminKutrl
__('Date') => 'kut_dt', __('Date') => 'kut_dt',
__('Short link') => 'kut_hash', __('Short link') => 'kut_hash',
__('Long link') => 'kut_url', __('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( $favs->register(
'kUtRL', 'kUtRL',
[ [
'title' => __('Links shortener'), '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'), 'small-icon' => dcPage::getPF('kUtRL/icon.png'),
'large-icon' => dcPage::getPF('kUtRL/icon-b.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'] = [ $cols['kUtRL'] = [
__('Links shortener'), __('Links shortener'),
[ [
'kut_hash' => [true, __('Hash')], 'kut_hash' => [true, __('Hash')],
'kut_dt' => [true, __('Date')], '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'] = [ $sorts['kUtRL'] = [
__('Links shortener'), __('Links shortener'),
self::sortbyCombo(), self::sortbyCombo(),
'kut_dt', 'kut_dt',
'desc', 'desc',
[__('links per page'), 30] [__('links per page'), 30],
]; ];
} }
@ -105,13 +104,12 @@ class adminKutrl
public static function adminPostFormItems($main_items, $sidebar_items, $post) public static function adminPostFormItems($main_items, $sidebar_items, $post)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active || !$s->kutrl_admin_service) { if (!$s->kutrl_active || !$s->kutrl_admin_service) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('admin'))) { if (null === ($kut = kUtRL::quickPlace('admin'))) {
return null; return null;
} }
@ -165,14 +163,13 @@ class adminKutrl
public static function adminAfterPostUpdate($cur, $post_id) public static function adminAfterPostUpdate($cur, $post_id)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
# Create: see adminAfterPostCreate # Create: see adminAfterPostCreate
if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) { if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('admin'))) { if (null === ($kut = kUtRL::quickPlace('admin'))) {
return null; return null;
} }
if (empty($_POST['kutrl_old_post_url'])) { if (empty($_POST['kutrl_old_post_url'])) {
@ -185,7 +182,7 @@ class adminKutrl
return null; return null;
} }
$rs = $core->blog->getPosts(['post_id' => $post_id]); $rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;
} }
@ -208,24 +205,23 @@ class adminKutrl
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title); dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, $title);
} }
} }
} }
public static function adminAfterPostCreate($cur, $post_id) public static function adminAfterPostCreate($cur, $post_id)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (empty($_POST['kutrl_create']) || !$s->kutrl_active) { if (empty($_POST['kutrl_create']) || !$s->kutrl_active) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('admin'))) { if (null === ($kut = kUtRL::quickPlace('admin'))) {
return null; return null;
} }
$rs = $core->blog->getPosts(['post_id' => $post_id]); $rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;
} }
@ -239,23 +235,22 @@ class adminKutrl
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title); dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, $title);
} }
} }
public static function adminBeforePostDelete($post_id) public static function adminBeforePostDelete($post_id)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active) { if (!$s->kutrl_active) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('admin'))) { if (null === ($kut = kUtRL::quickPlace('admin'))) {
return null; return null;
} }
$rs = $core->blog->getPosts(['post_id' => $post_id]); $rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;
} }
@ -263,75 +258,102 @@ class adminKutrl
$kut->remove($rs->getURL()); $kut->remove($rs->getURL());
} }
public static function adminPostsActionsCombo($args) public static function adminPostsActions(dcPostsActions $pa)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active if (!$s->kutrl_active
|| !$core->auth->check('admin', $core->blog->id)) { || !dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)) {
return null; return null;
} }
$args[0][__('Links shortener')][__('Create short link')] = 'kutrl_create'; $pa->addAction(
$args[0][__('Links shortener')][__('Delete short link')] = 'kutrl_delete'; [__('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' if (null === ($kut = kUtRL::quickPlace('admin'))) {
&& $action != 'kutrl_delete') {
return null;
}
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) {
return null; 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()) { while ($posts->fetch()) {
$url = $posts->getURL(); $kut->hash($posts->getURL());
}
if ($action == 'kutrl_create') { dcAdminNotices::addSuccessNotice(__('Posts short links have been created.'));
$kut->hash($url); $pa->redirect(true);
} }
if ($action == 'kutrl_delete') {
$kut->remove($url); 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'));
} }
$core->blog->triggerBlog();
http::redirect($redir . '&done=1'); # 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 # Import/export behaviors for Import/export plugin
class backupKutrl class backupKutrl
{ {
public static function exportSingle($core, $exp, $blog_id) public static function exportSingle($exp, $blog_id)
{ {
$exp->export( $exp->export(
'kutrl', 'kutrl',
'SELECT kut_id, blog_id, kut_service, kut_type, ' . 'SELECT kut_id, blog_id, kut_service, kut_type, ' .
'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' . 'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' .
'FROM ' . $core->prefix . 'kutrl ' . 'FROM ' . dcCore::app()->prefix . 'kutrl ' .
"WHERE blog_id = '" . $blog_id . "' " "WHERE blog_id = '" . $blog_id . "' "
); );
} }
public static function exportFull($core, $exp) public static function exportFull($exp)
{ {
$exp->exportTable('kutrl'); $exp->exportTable('kutrl');
} }
public static function importInit($bk, $core) public static function importInit($bk)
{ {
$bk->cur_kutrl = $core->con->openCursor($core->prefix . 'kutrl'); $bk->cur_kutrl = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'kutrl');
$bk->kutrl = new kutrlLog($core); $bk->kutrl = new kutrlLog();
} }
public static function importSingle($line, $bk, $core) public static function importSingle($line, $bk)
{ {
if ($line->__name == 'kutrl') { if ($line->__name == 'kutrl') {
# Do nothing if str/type exists ! # 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') { if ($line->__name == 'kutrl') {
$bk->cur_kutrl->clean(); $bk->cur_kutrl->clean();

View File

@ -15,18 +15,18 @@ if (!defined('DC_CONTEXT_ADMIN')) {
} }
# Check user perms # Check user perms
dcPage::check('admin'); dcPage::check(dcAuth::PERMISSION_ADMIN);
# Settings # Settings
$s = $core->blog->settings->kUtRL; $s = dcCore::app()->blog->settings->kUtRL;
# Default values # Default values
$img_green = '<img src="images/check-on.png" alt="ok" />'; $img_green = '<img src="images/check-on.png" alt="ok" />';
$img_red = '<img src="images/check-off.png" alt="fail" />'; $img_red = '<img src="images/check-off.png" alt="fail" />';
$services_combo = []; $services_combo = [];
foreach (kutrl::getServices($core) as $service_id => $service) { foreach (kUtRL::getServices() as $service_id => $service) {
$o = new $service($core); $o = new $service();
$services_combo[__($o->name)] = $o->id; $services_combo[__($o->name)] = $o->id;
} }
$ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); $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); $s->put('kutrl_admin_entry_default', $s_admin_entry_default);
# services # services
foreach (kutrl::getServices($core) as $service_id => $service) { foreach (kUtRL::getServices() as $service_id => $service) {
$o = new $service($core); $o = new $service();
$o->saveSettings(); $o->saveSettings();
} }
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
$core->adminurl->redirect( dcCore::app()->adminurl->redirect(
'admin.plugins', '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) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -121,7 +121,7 @@ __('Create short link for new entries') . '</label></p>
<h5>' . __('Default services') . '</h5> <h5>' . __('Default services') . '</h5>
<p><label>'; <p><label>';
if (!empty($_REQUEST['chk'])) { if (!empty($_REQUEST['chk'])) {
if (null !== ($o = kutrl::quickPlace($s_admin_service))) { if (null !== ($o = kUtRL::quickPlace($s_admin_service))) {
echo $o->testService() ? $img_green : $img_red; echo $o->testService() ? $img_green : $img_red;
} }
} }
@ -131,7 +131,7 @@ form::combo(['s_admin_service'], $services_combo, $s_admin_service) . '
<p class="form-note">' . __('Service to use in this admin page and on edit page of an entry.') . '</p> <p class="form-note">' . __('Service to use in this admin page and on edit page of an entry.') . '</p>
<p><label>'; <p><label>';
if (!empty($_REQUEST['chk'])) { if (!empty($_REQUEST['chk'])) {
if (null !== ($o = kutrl::quickPlace($s_plugin_service))) { if (null !== ($o = kUtRL::quickPlace($s_plugin_service))) {
echo $o->testService() ? $img_green : $img_red; echo $o->testService() ? $img_green : $img_red;
} }
} }
@ -141,7 +141,7 @@ form::combo(['s_plugin_service'], $services_combo, $s_plugin_service) . '
<p class="form-note">' . __('Service to use on third part plugins.') . '</p> <p class="form-note">' . __('Service to use on third part plugins.') . '</p>
<p><label>'; <p><label>';
if (!empty($_REQUEST['chk'])) { if (!empty($_REQUEST['chk'])) {
if (null !== ($o = kutrl::quickPlace($s_tpl_service))) { if (null !== ($o = kUtRL::quickPlace($s_tpl_service))) {
echo $o->testService() ? $img_green : $img_red; echo $o->testService() ? $img_green : $img_red;
} }
} }
@ -151,7 +151,7 @@ form::combo(['s_tpl_service'], $ext_services_combo, $s_tpl_service) . '
<p class="form-note">' . __('Shorten links automatically when using template value like "EntryKutrl".') . '</p> <p class="form-note">' . __('Shorten links automatically when using template value like "EntryKutrl".') . '</p>
<p><label>'; <p><label>';
if (!empty($_REQUEST['chk'])) { if (!empty($_REQUEST['chk'])) {
if (null !== ($o = kutrl::quickPlace($s_wiki_service))) { if (null !== ($o = kUtRL::quickPlace($s_wiki_service))) {
echo $o->testService() ? $img_green : $img_red; echo $o->testService() ? $img_green : $img_red;
} }
} }
@ -167,8 +167,8 @@ form::combo(['s_wiki_service'], $ext_services_combo, $s_wiki_service) . '
<p class="info">' . __('List of services you can use to shorten links with pkugin kUtRL.') . '</p> <p class="info">' . __('List of services you can use to shorten links with pkugin kUtRL.') . '</p>
'; ';
foreach (kutrl::getServices($core) as $service_id => $service) { foreach (kUtRL::getServices() as $service_id => $service) {
$o = new $service($core); $o = new $service();
echo '<hr/><div id="setting-' . $service_id . '"><h5>' . $o->name . '</h5>'; echo '<hr/><div id="setting-' . $service_id . '"><h5>' . $o->name . '</h5>';
@ -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); $img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name);
} }
} catch (Exception $e) { } 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('<p><em>%s</em></p>', $img_chk) . $o->error->toHTML(); echo sprintf('<p><em>%s</em></p>', $img_chk) . $o->error->toHTML();
} }

View File

@ -18,13 +18,17 @@ $this->registerModule(
'Links shortener', 'Links shortener',
'Use, create and serve short url on your blog', 'Use, create and serve short url on your blog',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'2021.11.06', '2022.11.12',
[ [
'requires' => [['core', '2.20']], 'requires' => [['core', '2.24']],
'permissions' => 'usage,contentadmin,admin', 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
dcAuth::PERMISSION_ADMIN,
]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/kUtRL', 'support' => 'https://github.com/JcDenis/kUtRL',
'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL', 'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL',
'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml' 'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml',
] ]
); );

View File

@ -15,8 +15,8 @@ if (!defined('DC_CONTEXT_ADMIN')) {
} }
# Get new version # Get new version
$new_version = $core->plugins->moduleInfo('kUtRL', 'version'); $new_version = dcCore::app()->plugins->moduleInfo('kUtRL', 'version');
$old_version = $core->getVersion('kUtRL'); $old_version = dcCore::app()->getVersion('kUtRL');
# Compare versions # Compare versions
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
@ -26,7 +26,7 @@ if (version_compare($old_version, $new_version, '>=')) {
# Install or update # Install or update
try { try {
# Table # Table
$t = new dbStruct($core->con, $core->prefix); $t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$t->kutrl $t->kutrl
->kut_id('bigint', 0, false) ->kut_id('bigint', 0, false)
->blog_id('varchar', 32, false) ->blog_id('varchar', 32, false)
@ -44,12 +44,12 @@ try {
->index('idx_kut_service', 'btree', 'kut_service') ->index('idx_kut_service', 'btree', 'kut_service')
->index('idx_kut_type', 'btree', 'kut_type'); ->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); $changes = $ti->synchronize($t);
# Settings # Settings
$core->blog->settings->addNamespace('kUtRL'); dcCore::app()->blog->settings->addNamespace('kUtRL');
$s = $core->blog->settings->kUtRL; $s = dcCore::app()->blog->settings->kUtRL;
$s->put('kutrl_active', false, 'boolean', 'Enabled kutrl plugin', false, true); $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_plugin_service', 'default', 'string', 'Service to use to shorten links on third part plugins', false, true);
$s->put('kutrl_admin_service', 'local', 'string', 'Service to use to shorten links on admin', false, true); $s->put('kutrl_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); $s->put('kutrl_srv_yourls_password', '', 'string', 'User password to YOURLS service', false, true);
# Version # Version
$core->setVersion('kUtRL', $new_version); dcCore::app()->setVersion('kUtRL', $new_version);
# Get dcMiniUrl records as this plugin do the same # Get dcMiniUrl records as this plugin do the same
if ($core->plugins->moduleExists('dcMiniUrl')) { if (dcCore::app()->plugins->moduleExists('dcMiniUrl')) {
require_once dirname(__FILE__) . '/inc/patch.dcminiurl.php'; require_once __DIR__ . '/inc/patch.dcminiurl.php';
} }
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return false; return false;

View File

@ -32,66 +32,66 @@ if (!defined('SHORTEN_SERVICE_ENCODE')) {
} }
# Main class # Main class
$d = dirname(__FILE__) . '/inc/'; $d = __DIR__ . '/inc/';
$__autoload['kutrl'] = $d . 'class.kutrl.php'; Clearbricks::lib()->autoload(['kUtRL' => $d . 'class.kutrl.php']);
$__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php'; Clearbricks::lib()->autoload(['kutrlService' => $d . 'lib.kutrl.srv.php']);
$__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php'; Clearbricks::lib()->autoload(['kutrlLog' => $d . 'lib.kutrl.log.php']);
$__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php'; Clearbricks::lib()->autoload(['kutrlLinkslist' => $d . 'lib.kutrl.lst.php']);
# Services # Services
$__autoload['defaultKutrlService'] = $d . 'services/class.default.service.php'; Clearbricks::lib()->autoload(['defaultKutrlService' => $d . 'services/class.default.service.php']);
$core->addBehavior('kutrlService', function () { return ['default','defaultKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['default','defaultKutrlService']; });
if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) { if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) {
$__autoload['customKutrlService'] = $d . 'services/class.custom.service.php'; Clearbricks::lib()->autoload(['customKutrlService' => $d . 'services/class.custom.service.php']);
$core->addBehavior('kutrlService', function () { return ['custom','customKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['custom','customKutrlService']; });
} }
if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) { if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) {
$__autoload['localKutrlService'] = $d . 'services/class.local.service.php'; Clearbricks::lib()->autoload(['localKutrlService' => $d . 'services/class.local.service.php']);
$core->addBehavior('kutrlService', function () { return ['local','localKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['local','localKutrlService']; });
} }
if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) { if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) {
$__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php'; Clearbricks::lib()->autoload(['bilbolinksKutrlService' => $d . 'services/class.bilbolinks.service.php']);
$core->addBehavior('kutrlService', function () { return ['bilbolinks','bilbolinksKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['bilbolinks','bilbolinksKutrlService']; });
} }
if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) { if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) {
$__autoload['bitlyKutrlService'] = $d . 'services/class.bitly.service.php'; Clearbricks::lib()->autoload(['bitlyKutrlService' => $d . 'services/class.bitly.service.php']);
$core->addBehavior('kutrlService', function () { return ['bitly','bitlyKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['bitly','bitlyKutrlService']; });
} }
//if (!defined('SHORTEN_SERVICE_DISABLE_GOOGL')) { //if (!defined('SHORTEN_SERVICE_DISABLE_GOOGL')) {
// $__autoload['googlKutrlService'] = $d . 'services/class.googl.service.php'; // Clearbricks::lib()->autoload(['googlKutrlService' => $d . 'services/class.googl.service.php']);
// $core->addBehavior('kutrlService', function() { return ["googl","googlKutrlService"]; } ); // dcCore::app()->addBehavior('kutrlService', function() { return ["googl","googlKutrlService"]; } );
//} //}
if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) { if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) {
$__autoload['isgdKutrlService'] = $d . 'services/class.isgd.service.php'; Clearbricks::lib()->autoload(['isgdKutrlService' => $d . 'services/class.isgd.service.php']);
$core->addBehavior('kutrlService', function () { return ['isgd','isgdKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['isgd','isgdKutrlService']; });
} }
//if (!defined('SHORTEN_SERVICE_DISABLE_SHORTTO')) { //if (!defined('SHORTEN_SERVICE_DISABLE_SHORTTO')) {
// $__autoload['shorttoKutrlService'] = $d . 'services/class.shortto.service.php'; // Clearbricks::lib()->autoload(['shorttoKutrlService' => $d . 'services/class.shortto.service.php']);
// $core->addBehavior('kutrlService', function() { return ["shortto","shorttoKutrlService"]; } ); // dcCore::app()->addBehavior('kutrlService', function() { return ["shortto","shorttoKutrlService"]; } );
//} //}
//if (!defined('SHORTEN_SERVICE_DISABLE_TRIM')) { //if (!defined('SHORTEN_SERVICE_DISABLE_TRIM')) {
// $__autoload['trimKutrlService'] = $d . 'services/class.trim.service.php'; // Clearbricks::lib()->autoload(['trimKutrlService' => $d . 'services/class.trim.service.php']);
// $core->addBehavior('kutrlService', function() { return ["trim","trimKutrlService"]; } ); // dcCore::app()->addBehavior('kutrlService', function() { return ["trim","trimKutrlService"]; } );
//} //}
if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) { if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) {
$__autoload['yourlsKutrlService'] = $d . 'services/class.yourls.service.php'; Clearbricks::lib()->autoload(['yourlsKutrlService' => $d . 'services/class.yourls.service.php']);
$core->addBehavior('kutrlService', function () { return ['yourls','yourlsKutrlService']; }); dcCore::app()->addBehavior('kutrlService', function () { return ['yourls','yourlsKutrlService']; });
} }
//if (!defined('SHORTEN_SERVICE_DISABLE_SUPR')) { //if (!defined('SHORTEN_SERVICE_DISABLE_SUPR')) {
// $__autoload['suprKutrlService'] = $d . 'services/class.supr.service.php'; // Clearbricks::lib()->autoload(['suprKutrlService' => $d . 'services/class.supr.service.php']);
// $core->addBehavior('kutrlService', function() { return ["supr","suprKutrlService"]; } ); // dcCore::app()->addBehavior('kutrlService', function() { return ["supr","suprKutrlService"]; } );
//} //}
# Shorten url passed through wiki functions # Shorten url passed through wiki functions
$__autoload['kutrlWiki'] = $d . 'lib.wiki.kutrl.php'; Clearbricks::lib()->autoload(['kutrlWiki' => $d . 'lib.wiki.kutrl.php']);
$core->addBehavior('coreInitWikiPost', ['kutrlWiki','coreInitWiki']); dcCore::app()->addBehavior('coreInitWikiPost', ['kutrlWiki','coreInitWiki']);
$core->addBehavior('coreInitWikiComment', ['kutrlWiki','coreInitWiki']); dcCore::app()->addBehavior('coreInitWikiComment', ['kutrlWiki','coreInitWiki']);
$core->addBehavior('coreInitWikiSimpleComment', ['kutrlWiki','coreInitWiki']); dcCore::app()->addBehavior('coreInitWikiSimpleComment', ['kutrlWiki','coreInitWiki']);
# Public page # 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 # Add kUtRL events on plugin activityReport
if (defined('ACTIVITY_REPORT')) { if (defined('ACTIVITY_REPORT_V2')) {
require_once $d . 'lib.kutrl.activityreport.php'; require_once $d . 'lib.kutrl.activityreport.php';
} }

View File

@ -14,44 +14,43 @@ if (!defined('DC_RC_PATH')) {
return null; 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']); dcCore::app()->addBehavior('publicBeforeDocumentV2', ['pubKutrl', 'publicBeforeDocument']);
$core->addBehavior('publicHeadContent', ['pubKutrl', 'publicHeadContent']); dcCore::app()->addBehavior('publicHeadContent', ['pubKutrl', 'publicHeadContent']);
$core->addBehavior('publicBeforeContentFilter', ['pubKutrl', 'publicBeforeContentFilter']); dcCore::app()->addBehavior('publicBeforeContentFilterV2', ['pubKutrl', 'publicBeforeContentFilter']);
$core->addBehavior('templateBeforeValue', ['pubKutrl', 'templateBeforeValue']); dcCore::app()->addBehavior('templateBeforeValueV2', ['pubKutrl', 'templateBeforeValue']);
$core->addBehavior('templateAfterValue', ['pubKutrl', 'templateAfterValue']); dcCore::app()->addBehavior('templateAfterValueV2', ['pubKutrl', 'templateAfterValue']);
$core->tpl->addBlock('kutrlPageIf', ['tplKutrl', 'pageIf']); dcCore::app()->tpl->addBlock('kutrlPageIf', ['tplKutrl', 'pageIf']);
$core->tpl->addBlock('kutrlMsgIf', ['tplKutrl', 'pageMsgIf']); dcCore::app()->tpl->addBlock('kutrlMsgIf', ['tplKutrl', 'pageMsgIf']);
$core->tpl->addValue('kutrlPageURL', ['tplKutrl', 'pageURL']); dcCore::app()->tpl->addValue('kutrlPageURL', ['tplKutrl', 'pageURL']);
$core->tpl->addValue('kutrlMsg', ['tplKutrl', 'pageMsg']); dcCore::app()->tpl->addValue('kutrlMsg', ['tplKutrl', 'pageMsg']);
$core->tpl->addValue('kutrlHumanField', ['tplKutrl', 'humanField']); dcCore::app()->tpl->addValue('kutrlHumanField', ['tplKutrl', 'humanField']);
$core->tpl->addValue('kutrlHumanFieldProtect', ['tplKutrl', 'humanFieldProtect']); dcCore::app()->tpl->addValue('kutrlHumanFieldProtect', ['tplKutrl', 'humanFieldProtect']);
$core->tpl->addBlock('AttachmentKutrlIf', ['tplKutrl', 'AttachmentKutrlIf']); dcCore::app()->tpl->addBlock('AttachmentKutrlIf', ['tplKutrl', 'AttachmentKutrlIf']);
$core->tpl->addValue('AttachmentKutrl', ['tplKutrl', 'AttachmentKutrl']); dcCore::app()->tpl->addValue('AttachmentKutrl', ['tplKutrl', 'AttachmentKutrl']);
$core->tpl->addBlock('MediaKutrlIf', ['tplKutrl', 'MediaKutrlIf']); dcCore::app()->tpl->addBlock('MediaKutrlIf', ['tplKutrl', 'MediaKutrlIf']);
$core->tpl->addValue('MediaKutrl', ['tplKutrl', 'MediaKutrl']); dcCore::app()->tpl->addValue('MediaKutrl', ['tplKutrl', 'MediaKutrl']);
$core->tpl->addBlock('EntryAuthorKutrlIf', ['tplKutrl', 'EntryAuthorKutrlIf']); dcCore::app()->tpl->addBlock('EntryAuthorKutrlIf', ['tplKutrl', 'EntryAuthorKutrlIf']);
$core->tpl->addValue('EntryAuthorKutrl', ['tplKutrl', 'EntryAuthorKutrl']); dcCore::app()->tpl->addValue('EntryAuthorKutrl', ['tplKutrl', 'EntryAuthorKutrl']);
$core->tpl->addBlock('EntryKutrlIf', ['tplKutrl', 'EntryKutrlIf']); dcCore::app()->tpl->addBlock('EntryKutrlIf', ['tplKutrl', 'EntryKutrlIf']);
$core->tpl->addValue('EntryKutrl', ['tplKutrl', 'EntryKutrl']); dcCore::app()->tpl->addValue('EntryKutrl', ['tplKutrl', 'EntryKutrl']);
$core->tpl->addBlock('CommentAuthorKutrlIf', ['tplKutrl', 'CommentAuthorKutrlIf']); dcCore::app()->tpl->addBlock('CommentAuthorKutrlIf', ['tplKutrl', 'CommentAuthorKutrlIf']);
$core->tpl->addValue('CommentAuthorKutrl', ['tplKutrl', 'CommentAuthorKutrl']); dcCore::app()->tpl->addValue('CommentAuthorKutrl', ['tplKutrl', 'CommentAuthorKutrl']);
$core->tpl->addBlock('CommentPostKutrlIf', ['tplKutrl', 'CommentPostKutrlIf']); dcCore::app()->tpl->addBlock('CommentPostKutrlIf', ['tplKutrl', 'CommentPostKutrlIf']);
$core->tpl->addValue('CommentPostKutrl', ['tplKutrl', 'CommentPostKutrl']); dcCore::app()->tpl->addValue('CommentPostKutrl', ['tplKutrl', 'CommentPostKutrl']);
class urlKutrl extends dcUrlHandlers class urlKutrl extends dcUrlHandlers
{ {
# Redirect !!! local !!! service only # Redirect !!! local !!! service only
public static function redirectUrl($args) public static function redirectUrl($args)
{ {
global $core, $_ctx; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
# Not active, go to default 404 # Not active, go to default 404
if (!$s->kutrl_active) { if (!$s->kutrl_active) {
@ -67,15 +66,15 @@ class urlKutrl extends dcUrlHandlers
} }
$args = $m[3] ?? ''; $args = $m[3] ?? '';
$_ctx->kutrl_msg = ''; dcCore::app()->ctx->kutrl_msg = '';
$_ctx->kutrl_hmf = hmfKutrl::create(); dcCore::app()->ctx->kutrl_hmf = hmfKutrl::create();
$_ctx->kutrl_hmfp = hmfKutrl::protect($_ctx->kutrl_hmf); dcCore::app()->ctx->kutrl_hmfp = hmfKutrl::protect(dcCore::app()->ctx->kutrl_hmf);
$kut = new localKutrlService($core); $kut = new localKutrlService();
# Nothing on url # Nothing on url
if ($m[1] == '/') { if ($m[1] == '/') {
$_ctx->kutrl_msg = 'No link given.'; dcCore::app()->ctx->kutrl_msg = 'No link given.';
} }
# find suffix on redirect url # find suffix on redirect url
$suffix = ''; $suffix = '';
@ -104,7 +103,7 @@ class urlKutrl extends dcUrlHandlers
return null; return null;
} }
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
http::redirect($url . $suffix); http::redirect($url . $suffix);
return null; return null;
@ -112,8 +111,7 @@ class urlKutrl extends dcUrlHandlers
private static function pageKutrl($kut) private static function pageKutrl($kut)
{ {
global $core, $_ctx; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
# Not active, go to default 404 # Not active, go to default 404
if (!$s->kutrl_active) { if (!$s->kutrl_active) {
@ -128,7 +126,7 @@ class urlKutrl extends dcUrlHandlers
return null; return null;
} }
# Validation form # 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)) { if (!empty($url)) {
$hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!'; $hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!';
$hmfu = !empty($_POST['hmfp']) ? hmfKutrl::unprotect($_POST['hmfp']) : '?'; $hmfu = !empty($_POST['hmfp']) ? hmfKutrl::unprotect($_POST['hmfp']) : '?';
@ -137,44 +135,44 @@ class urlKutrl extends dcUrlHandlers
if (!$err) { if (!$err) {
if ($hmf != $hmfu) { if ($hmf != $hmfu) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Failed to verify protected field.'); dcCore::app()->ctx->kutrl_msg = __('Failed to verify protected field.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->testService()) { if (!$kut->testService()) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Service is not well configured.'); dcCore::app()->ctx->kutrl_msg = __('Service is not well configured.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isValidUrl($url)) { if (!$kut->isValidUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This string is not a valid URL.'); dcCore::app()->ctx->kutrl_msg = __('This string is not a valid URL.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isLongerUrl($url)) { if (!$kut->isLongerUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This link is too short.'); dcCore::app()->ctx->kutrl_msg = __('This link is too short.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isProtocolUrl($url)) { if (!$kut->isProtocolUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This type of link is not allowed.'); dcCore::app()->ctx->kutrl_msg = __('This type of link is not allowed.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) { if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Short links are limited to this blog URL.'); dcCore::app()->ctx->kutrl_msg = __('Short links are limited to this blog URL.');
} }
} }
if (!$err) { if (!$err) {
if ($kut->isServiceUrl($url)) { if ($kut->isServiceUrl($url)) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('This link is already a short link.'); dcCore::app()->ctx->kutrl_msg = __('This link is already a short link.');
} }
} }
if (!$err) { if (!$err) {
@ -184,7 +182,7 @@ class urlKutrl extends dcUrlHandlers
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
$_ctx->kutrl_msg = sprintf( dcCore::app()->ctx->kutrl_msg = sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
html::escapeHTML($url), html::escapeHTML($url),
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
@ -194,27 +192,27 @@ class urlKutrl extends dcUrlHandlers
if (!$err) { if (!$err) {
if (false === ($rs = $kut->hash($url))) { if (false === ($rs = $kut->hash($url))) {
$err = true; $err = true;
$_ctx->kutrl_msg = __('Failed to create short link.'); dcCore::app()->ctx->kutrl_msg = __('Failed to create short link.');
} else { } else {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
$_ctx->kutrl_msg = sprintf( dcCore::app()->ctx->kutrl_msg = sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
html::escapeHTML($url), html::escapeHTML($url),
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
); );
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { 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'); self::serveDocument('kutrl.html');
return null; return null;
@ -222,28 +220,24 @@ class urlKutrl extends dcUrlHandlers
protected static function kutrl404() protected static function kutrl404()
{ {
global $core; if (!dcCore::app()->blog->settings->kUtRL->kutrl_srv_local_404_active) {
if (!$core->blog->settings->kUtRL->kutrl_srv_local_404_active) {
self::p404(); self::p404();
return null; return null;
} }
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__) . '/default-templates'); dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates');
$_ctx = & $GLOBALS['_ctx'];
$core = $GLOBALS['core'];
header('Content-Type: text/html; charset=UTF-8'); header('Content-Type: text/html; charset=UTF-8');
http::head(404, 'Not Found'); http::head(404, 'Not Found');
$core->url->type = '404'; dcCore::app()->url->type = '404';
$_ctx->current_tpl = 'kutrl404.html'; dcCore::app()->ctx->current_tpl = 'kutrl404.html';
$_ctx->content_type = 'text/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 # --BEHAVIOR-- publicAfterDocument
$core->callBehavior('publicAfterDocument', $core); dcCore::app()->callBehavior('publicAfterDocumentV2');
exit; exit;
} }
} }
@ -259,11 +253,11 @@ class pubKutrl
'EntryURL', 'EntryURL',
'EntryCategoryURL', 'EntryCategoryURL',
'CommentAuthorURL', 'CommentAuthorURL',
'CommentPostURL' 'CommentPostURL',
]; ];
# Disable URL shoretning on filtered tag # 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)) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) {
return '<?php $GLOBALS["disable_kutrl"] = true; ?>'; return '<?php $GLOBALS["disable_kutrl"] = true; ?>';
@ -273,7 +267,7 @@ class pubKutrl
} }
# Re unable it after tag # 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)) { if (!empty($attr['disable_kutrl']) && in_array($tag, pubKutrl::$know_tags)) {
return '<?php $GLOBALS["disable_kutrl"] = false; ?>'; return '<?php $GLOBALS["disable_kutrl"] = false; ?>';
@ -283,7 +277,7 @@ class pubKutrl
} }
# Replace long urls on the fly (on filter) for default tags # 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 # Unknow tag
if (!in_array($tag, pubKutrl::$know_tags)) { if (!in_array($tag, pubKutrl::$know_tags)) {
@ -292,53 +286,50 @@ class pubKutrl
# URL shortening is disabled by tag attribute # URL shortening is disabled by tag attribute
if (empty($GLOBALS['disable_kutrl'])) { if (empty($GLOBALS['disable_kutrl'])) {
# kUtRL is not activated # kUtRL is not activated
if (!$core->blog->settings->kUtRL->kutrl_active if (!dcCore::app()->blog->settings->kUtRL->kutrl_active
|| !$core->blog->settings->kUtRL->kutrl_tpl_active || !dcCore::app()->blog->settings->kUtRL->kutrl_tpl_active
) { ) {
return null; return null;
} }
global $_ctx;
# Oups # Oups
if (!$_ctx->exists('kutrl')) { if (!dcCore::app()->ctx->exists('kutrl')) {
return null; return null;
} }
# Existing # Existing
if (false !== ($kutrl_rs = $_ctx->kutrl->isKnowUrl($args[0]))) { if (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->isKnowUrl($args[0]))) {
$args[0] = $_ctx->kutrl->url_base . $kutrl_rs->hash; $args[0] = dcCore::app()->ctx->kutrl->url_base . $kutrl_rs->hash;
# New # New
} elseif (false !== ($kutrl_rs = $_ctx->kutrl->hash($args[0]))) { } elseif (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->hash($args[0]))) {
$args[0] = $_ctx->kutrl->url_base . $kutrl_rs->hash; $args[0] = dcCore::app()->ctx->kutrl->url_base . $kutrl_rs->hash;
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($kutrl_rs)) { 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 = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
# Passive : all kutrl tag return long url # 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) { if (!$s->kutrl_active || !$s->kutrl_tpl_service) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('tpl'))) { if (null === ($kut = kUtRL::quickPlace('tpl'))) {
return null; return null;
} }
$_ctx->kutrl = $kut; dcCore::app()->ctx->kutrl = $kut;
} }
public static function publicHeadContent($core) 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) { if ($css) {
echo echo
"\n<!-- CSS for kUtRL --> \n" . "\n<!-- CSS for kUtRL --> \n" .
@ -353,9 +344,9 @@ class tplKutrl
{ {
public static function pageURL($attr) public static function pageURL($attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = dcCore::app()->tpl->getFilters($attr);
return '<?php echo ' . sprintf($f, '$core->blog->url.$core->url->getBase("kutrl")') . '; ?>'; return '<?php echo ' . sprintf($f, 'dcCore::app()->blog->url.dcCore::app()->url->getBase("kutrl")') . '; ?>';
} }
public static function pageIf($attr, $content) public static function pageIf($attr, $content)
@ -364,7 +355,7 @@ class tplKutrl
if (isset($attr['is_active'])) { if (isset($attr['is_active'])) {
$sign = (bool) $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)) { if (empty($if)) {
return $content; return $content;
@ -382,7 +373,7 @@ class tplKutrl
if (isset($attr['has_message'])) { if (isset($attr['has_message'])) {
$sign = (bool) $attr['has_message'] ? '!' : '='; $sign = (bool) $attr['has_message'] ? '!' : '=';
$if[] = '"" ' . $sign . '= $_ctx->kutrl_msg'; $if[] = '"" ' . $sign . '= dcCore::app()->ctx->kutrl_msg';
} }
if (empty($if)) { if (empty($if)) {
return $content; return $content;
@ -396,19 +387,19 @@ class tplKutrl
public static function pageMsg($attr) public static function pageMsg($attr)
{ {
return '<?php echo $_ctx->kutrl_msg; ?>'; return '<?php echo dcCore::app()->ctx->kutrl_msg; ?>';
} }
public static function humanField($attr) public static function humanField($attr)
{ {
return "<?php echo sprintf(__('Confirm by writing \"%s\" in next field:'),\$_ctx->kutrl_hmf); ?>"; return "<?php echo sprintf(__('Confirm by writing \"%s\" in next field:'),dcCore::app()->ctx->kutrl_hmf); ?>";
} }
public static function humanFieldProtect($attr) public static function humanFieldProtect($attr)
{ {
return return
'<input type="hidden" name="hmfp" id="hmfp" value="<?php echo $_ctx->kutrl_hmfp; ?>" />' . '<input type="hidden" name="hmfp" id="hmfp" value="<?php echo dcCore::app()->ctx->kutrl_hmfp; ?>" />' .
'<?php echo $core->formNonce(); ?>'; '<?php echo dcCore::app()->formNonce(); ?>';
} }
public static function AttachmentKutrlIf($attr, $content) public static function AttachmentKutrlIf($attr, $content)
@ -423,52 +414,52 @@ class tplKutrl
public static function MediaKutrlIf($attr, $content) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) protected static function genericKutrlIf($str, $attr, $content)
@ -477,15 +468,15 @@ class tplKutrl
if (isset($attr['is_active'])) { if (isset($attr['is_active'])) {
$sign = (bool) $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'])) { if (isset($attr['passive_mode'])) {
$sign = (bool) $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'])) { if (isset($attr['has_kutrl'])) {
$sign = (bool) $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)) { if (empty($if)) {
return $content; return $content;
@ -499,32 +490,32 @@ class tplKutrl
protected static function genericKutrl($str, $attr) protected static function genericKutrl($str, $attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = dcCore::app()->tpl->getFilters($attr);
return return
"<?php \n" . "<?php \n" .
# Preview # Preview
"if (\$_ctx->preview) { \n" . "if (dcCore::app()->ctx->preview) { \n" .
' echo ' . sprintf($f, $str) . '; ' . ' echo ' . sprintf($f, $str) . '; ' .
"} else { \n" . "} else { \n" .
# Disable # Disable
"if (!\$_ctx->exists('kutrl')) { \n" . "if (!dcCore::app()->ctx->exists('kutrl')) { \n" .
# Passive mode # Passive mode
' if ($_ctx->kutrl_passive) { ' . ' if (dcCore::app()->ctx->kutrl_passive) { ' .
' echo ' . sprintf($f, $str) . '; ' . ' echo ' . sprintf($f, $str) . '; ' .
" } \n" . " } \n" .
"} else { \n" . "} else { \n" .
# Existing # Existing
' if (false !== ($kutrl_rs = $_ctx->kutrl->isKnowUrl(' . $str . '))) { ' . ' if (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->isKnowUrl(' . $str . '))) { ' .
' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . ' echo ' . sprintf($f, 'dcCore::app()->ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' .
" } \n" . " } \n" .
# New # New
' elseif (false !== ($kutrl_rs = $_ctx->kutrl->hash(' . $str . '))) { ' . ' elseif (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->hash(' . $str . '))) { ' .
' echo ' . sprintf($f, '$_ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . ' echo ' . sprintf($f, 'dcCore::app()->ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' .
# ex: Send new url to messengers # ex: Send new url to messengers
' if (!empty($kutrl_rs)) { ' . ' 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" .
" } \n" . " } \n" .

View File

@ -14,8 +14,8 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->addBehavior('initWidgets', ['widgetKutrl', 'adminShorten']); dcCore::app()->addBehavior('initWidgets', ['widgetKutrl', 'adminShorten']);
$core->addBehavior('initWidgets', ['widgetKutrl', 'adminRank']); dcCore::app()->addBehavior('initWidgets', ['widgetKutrl', 'adminRank']);
class widgetKutrl class widgetKutrl
{ {
@ -64,7 +64,7 @@ class widgetKutrl
__('All') => '-', __('All') => '-',
__('Mini URL') => 'localnormal', __('Mini URL') => 'localnormal',
__('Custom URL') => 'localcustom', __('Custom URL') => 'localcustom',
__('Semi-custom') => 'localmix' __('Semi-custom') => 'localmix',
] ]
) )
->setting( ->setting(
@ -81,7 +81,7 @@ class widgetKutrl
[ [
__('Date') => 'kut_dt', __('Date') => 'kut_dt',
__('Rank') => 'kut_counter', __('Rank') => 'kut_counter',
__('Hash') => 'kut_hash' __('Hash') => 'kut_hash',
] ]
) )
->setting( ->setting(
@ -91,7 +91,7 @@ class widgetKutrl
'combo', 'combo',
[ [
__('Ascending') => 'asc', __('Ascending') => 'asc',
__('Descending') => 'desc' __('Descending') => 'desc',
] ]
) )
->setting( ->setting(
@ -114,13 +114,12 @@ class widgetKutrl
public static function publicShorten($w) public static function publicShorten($w)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active if (!$s->kutrl_active
|| !$s->kutrl_srv_local_public || !$s->kutrl_srv_local_public
|| ($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))
|| $core->url->type == 'kutrl') { || dcCore::app()->url->type == 'kutrl') {
return null; return null;
} }
@ -133,7 +132,7 @@ class widgetKutrl
'', '',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
'<form name="shortenkutrlwidget" method="post" action="' . '<form name="shortenkutrlwidget" method="post" action="' .
$core->blog->url . $core->url->getBase('kutrl') . '">' . dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '">' .
'<p><label>' . '<p><label>' .
__('Long link:') . '<br />' . __('Long link:') . '<br />' .
form::field('longurl', 20, 255, '') . form::field('longurl', 20, 255, '') .
@ -144,7 +143,7 @@ class widgetKutrl
'</label></p>' . '</label></p>' .
'<p><input class="submit" type="submit" name="submiturl" value="' . __('Shorten') . '" />' . '<p><input class="submit" type="submit" name="submiturl" value="' . __('Shorten') . '" />' .
form::hidden('hmfp', $hmfp) . form::hidden('hmfp', $hmfp) .
$core->formNonce() . dcCore::app()->formNonce() .
'</p>' . '</p>' .
'</form>' '</form>'
); );
@ -152,23 +151,22 @@ class widgetKutrl
public static function publicRank($w) public static function publicRank($w)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active 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; return null;
} }
$type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ? $type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ?
"AND kut_type ='" . $w->type . "' " : "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 ' : ''; $hide = (bool) $w->hideempty ? 'AND kut_counter > 0 ' : '';
$more = ''; $more = '';
if ($w->type == 'localmix' && '' != $w->mixprefix) { 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'])) ? $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'; $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 ' . 'SELECT kut_counter, kut_hash ' .
'FROM ' . $core->prefix . 'kutrl ' . 'FROM ' . dcCore::app()->prefix . 'kutrl ' .
"WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . "WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
"AND kut_service = 'local' " . "AND kut_service = 'local' " .
$type . $hide . $more . 'ORDER BY ' . $order . $limit $type . $hide . $more . 'ORDER BY ' . $order . $limit
); );
@ -197,7 +195,7 @@ class widgetKutrl
$rank = '<span class="rankkutrl-rank">' . $i . '</span>'; $rank = '<span class="rankkutrl-rank">' . $i . '</span>';
$hash = $rs->kut_hash; $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); $cut_len = - abs((int) $w->urllen);
if (strlen($url) > $cut_len) { if (strlen($url) > $cut_len) {
@ -217,7 +215,7 @@ class widgetKutrl
} }
$content .= '<li><a href="' . $content .= '<li><a href="' .
$core->blog->url . $core->url->getBase('kutrl') . '/' . $rs->kut_hash . dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/' . $rs->kut_hash .
'">' . '">' .
str_replace( str_replace(
['%rank%', '%hash%', '%url%', '%count%', '%counttext%'], ['%rank%', '%hash%', '%url%', '%count%', '%counttext%'],

View File

@ -18,9 +18,9 @@ if (!defined('DC_RC_PATH')) {
class kUtRL class kUtRL
{ {
# Load services list from behavior # 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)) { if (empty($list)) {
return []; return [];
@ -28,7 +28,7 @@ class kUtRL
$services = []; $services = [];
foreach ($list as $k => $callback) { foreach ($list as $k => $callback) {
try { try {
list($service_id, $service_class) = call_user_func($callback); [$service_id, $service_class] = call_user_func($callback);
$services[(string) $service_id] = (string) $service_class; $services[(string) $service_id] = (string) $service_class;
} catch (Exception $e) { } catch (Exception $e) {
} }
@ -41,15 +41,13 @@ class kUtRL
# Return null on error else service on success # Return null on error else service on success
public static function quickService($id = '') public static function quickService($id = '')
{ {
global $core;
try { try {
if (empty($id)) { if (empty($id)) {
return null; return null;
} }
$services = self::getServices($core); $services = self::getServices();
if (isset($services[$id])) { if (isset($services[$id])) {
return new $services[$id]($core); return new $services[$id]();
} }
} catch (Exception $e) { } catch (Exception $e) {
} }
@ -61,13 +59,11 @@ class kUtRL
# Return null on error else service on success # Return null on error else service on success
public static function quickPlace($place = 'plugin') public static function quickPlace($place = 'plugin')
{ {
global $core;
try { try {
if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) { if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) {
return null; return null;
} }
$id = $core->blog->settings->kUtRL->get('kutrl_' . $place . '_service'); $id = dcCore::app()->blog->settings->kUtRL->get('kutrl_' . $place . '_service');
if (!empty($id)) { if (!empty($id)) {
return self::quickService($id); return self::quickService($id);
} }
@ -81,8 +77,6 @@ class kUtRL
# return long url on error else short url on success # return long url on error else short url on success
public static function quickReduce($url, $custom = null, $place = 'plugin') public static function quickReduce($url, $custom = null, $place = 'plugin')
{ {
global $core;
try { try {
$srv = self::quickPlace($place); $srv = self::quickPlace($place);
if (empty($srv)) { if (empty($srv)) {

View File

@ -16,10 +16,10 @@ if (!defined('DC_RC_PATH')) {
return null; 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 # from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'kutrl', 'kutrl',
'create', 'create',
__('Short link creation'), __('Short link creation'),
@ -34,6 +34,6 @@ class kutrlActivityReportBehaviors
{ {
$logs = [$rs->type,$rs->hash]; $logs = [$rs->type,$rs->hash];
$GLOBALS['core']->activityReport->addLog('kutrl', 'create', $logs); dcCore::app()->activityReport->addLog('kutrl', 'create', $logs);
} }
} }

View File

@ -14,17 +14,15 @@
class kutrlLog class kutrlLog
{ {
public $core;
public $table; public $table;
public $blog; public $blog;
public $con; public $con;
public function __construct(dcCore $core) public function __construct()
{ {
$this->core = $core; $this->table = dcCore::app()->prefix . 'kutrl';
$this->table = $core->prefix . 'kutrl'; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
$this->blog = $core->con->escape($core->blog->id); $this->con = dcCore::app()->con;
$this->con = $core->con;
} }
public function nextId() public function nextId()
@ -58,7 +56,7 @@ class kutrlLog
'hash' => $hash, 'hash' => $hash,
'type' => $type, 'type' => $type,
'service' => $service, 'service' => $service,
'counter ' => 0 'counter ' => 0,
]; ];
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();

View File

@ -12,15 +12,13 @@
*/ */
class kutrlLinkslist class kutrlLinkslist
{ {
protected $core;
protected $rs; protected $rs;
protected $rs_count; protected $rs_count;
protected $html_prev; protected $html_prev;
protected $html_next; 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 = &$rs;
$this->rs_count = $rs_count; $this->rs_count = $rs_count;
$this->html_prev = __('&#171; prev.'); $this->html_prev = __('&#171; prev.');
@ -29,7 +27,7 @@ class kutrlLinkslist
public function userColumns($type, $cols) 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 (is_array($cols_user) || $cols_user instanceof ArrayObject) {
if (isset($cols_user[$type])) { if (isset($cols_user[$type])) {
foreach ($cols_user[$type] as $cn => $cd) { foreach ($cols_user[$type] as $cn => $cd) {
@ -62,7 +60,7 @@ class kutrlLinkslist
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>', 'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>', 'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
'kut_dt' => '<th scope="col">' . __('Date') . '</th>', 'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
'kut_service' => '<th scope="col">' . __('Service') . '</th>' 'kut_service' => '<th scope="col">' . __('Service') . '</th>',
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns('kUtRL', $cols); $this->userColumns('kUtRL', $cols);
@ -101,7 +99,7 @@ class kutrlLinkslist
$type = $this->rs->kut_type; $type = $this->rs->kut_type;
$hash = $this->rs->kut_hash; $hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($type))) { if (null !== ($o = kUtRL::quickService($type))) {
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>'; $type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>'; $hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
} }
@ -117,11 +115,11 @@ class kutrlLinkslist
$hash . $hash .
'</td>', '</td>',
'kut_dt' => '<td class="nowrap count">' . 'kut_dt' => '<td class="nowrap count">' .
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')) .
'</td>', '</td>',
'kut_service' => '<td class="nowrap">' . 'kut_service' => '<td class="nowrap">' .
$type . $type .
'</td>' '</td>',
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);

View File

@ -14,20 +14,18 @@
# A service class must extends this one # A service class must extends this one
class kutrlService class kutrlService
{ {
public $core;
public $error; public $error;
public $settings; public $settings;
public $log; public $log;
protected $config = []; protected $config = [];
public function __construct($core) public function __construct()
{ {
$this->core = $core; $this->settings = dcCore::app()->blog->settings->kUtRL;
$this->settings = $core->blog->settings->kUtRL; $this->log = new kutrlLog();
$this->log = new kutrlLog($core);
$this->error = new dcError(); $this->error = new dcError();
$this->error->setHTMLFormat('%s', "%s\n"); //$this->error->setHTMLFormat('%s', "%s\n");
$this->init(); $this->init();
@ -49,7 +47,7 @@ class kutrlService
'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL',
'url_api' => '', 'url_api' => '',
'url_base' => '', 'url_base' => '',
'url_min_len' => 0 'url_min_len' => 0,
], ],
$this->config $this->config
); );
@ -130,7 +128,7 @@ class kutrlService
# Test if an url is from current blog # Test if an url is from current blog
public function isBlogUrl($url) public function isBlogUrl($url)
{ {
$base = $this->core->blog->url; $base = dcCore::app()->blog->url;
$url = substr($url, 0, strlen($base)); $url = substr($url, 0, strlen($base));
return $url == $base; return $url == $base;
@ -151,7 +149,7 @@ class kutrlService
# Create hash from url # Create hash from url
public function hash($url, $hash = null) public function hash($url, $hash = null)
{ {
$url = trim($this->core->con->escape($url)); $url = trim(dcCore::app()->con->escape($url));
if ('undefined' === $this->id) { if ('undefined' === $this->id) {
return false; return false;
} }
@ -176,10 +174,10 @@ class kutrlService
} }
$this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl'); $this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl');
$this->core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
# --BEHAVIOR-- kutrlAfterCreateShortUrl # --BEHAVIOR-- kutrlAfterCreateShortUrl
$this->core->callBehavior('kutrlAfterCreateShortUrl', $rs); dcCore::app()->callBehavior('kutrlAfterCreateShortUrl', $rs);
} }
return $rs; return $rs;

View File

@ -20,17 +20,16 @@ class kutrlWiki
{ {
public static function coreInitWiki($wiki2xhtml) public static function coreInitWiki($wiki2xhtml)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
# Do nothing on comment preview and post preview # Do nothing on comment preview and post preview
if (!empty($_POST['preview']) if (!empty($_POST['preview'])
|| !empty($GLOBALS['_ctx']) && $GLOBALS['_ctx']->preview || isset(dcCore::app()->ctx) && dcCore::app()->ctx->preview
|| !$s->kutrl_active || !$s->kutrl_active
) { ) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('wiki'))) { if (null === ($kut = kUtRL::quickPlace('wiki'))) {
return null; return null;
} }
foreach ($kut->allow_protocols as $protocol) { foreach ($kut->allow_protocols as $protocol) {
@ -43,13 +42,12 @@ class kutrlWiki
public static function transform($url, $content) public static function transform($url, $content)
{ {
global $core; $s = dcCore::app()->blog->settings->kUtRL;
$s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active) { if (!$s->kutrl_active) {
return null; return null;
} }
if (null === ($kut = kutrl::quickPlace('wiki'))) { if (null === ($kut = kUtRL::quickPlace('wiki'))) {
return []; return [];
} }
# Test if long url exists # Test if long url exists
@ -72,7 +70,7 @@ class kutrlWiki
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
$core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL')); dcCore::app()->callBehavior('wikiAfterKutrlCreate', $rs, __('New short URL'));
} }
return $res; return $res;

View File

@ -17,28 +17,26 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return; return;
} }
$miniurl_patch = new dcMiniUrl2kUtRL($core); $miniurl_patch = new dcMiniUrl2kUtRL();
if ($miniurl_patch->parseRecords()) { if ($miniurl_patch->parseRecords()) {
try { try {
$core->plugins->deactivateModule('dcMiniUrl'); dcCore::app()->plugins->deactivateModule('dcMiniUrl');
} catch (Exception $e) { } catch (Exception $e) {
//$core->error->add($e->getMessage()); //dcCore::app()->error->add($e->getMessage());
} }
} }
class dcMiniUrl2kUtRL class dcMiniUrl2kUtRL
{ {
public $core; public $con;
public $k_tb; public $k_tb;
public $m_tb; public $m_tb;
public function __construct($core) public function __construct()
{ {
$this->core = $core; $this->con = dcCore::app()->con;
$this->con = $core->con; $this->k_tb = dcCore::app()->prefix . 'kutrl';
$this->k_tb = $core->prefix . 'kutrl'; $this->m_tb = dcCore::app()->prefix . 'miniurl';
$this->m_tb = $core->prefix . 'miniurl';
} }
public function parseRecords() public function parseRecords()

View File

@ -19,7 +19,7 @@ class bilbolinksKutrlService extends kutrlService
protected $config = [ protected $config = [
'id' => 'bilbolinks', 'id' => 'bilbolinks',
'name' => 'BilboLinks', 'name' => 'BilboLinks',
'home' => 'http://www.tux-planet.fr/bilbobox/' 'home' => 'http://www.tux-planet.fr/bilbobox/',
]; ];
protected function init() protected function init()

View File

@ -29,7 +29,7 @@ class bitlyKutrlService extends kutrlService
]; ];
private $args = [ private $args = [
'apiKey' => '' 'apiKey' => '',
]; ];
protected function init() protected function init()

View File

@ -18,12 +18,12 @@ class customKutrlService extends kutrlService
{ {
protected $config = [ protected $config = [
'id' => 'custom', 'id' => 'custom',
'name' => 'Custom' 'name' => 'Custom',
]; ];
protected function init() 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)) { if (!is_array($config)) {
$config = []; $config = [];
} }
@ -42,7 +42,7 @@ class customKutrlService extends kutrlService
'url_api' => $_POST['kutrl_srv_custom_url_api'], 'url_api' => $_POST['kutrl_srv_custom_url_api'],
'url_base' => $_POST['kutrl_srv_custom_url_base'], 'url_base' => $_POST['kutrl_srv_custom_url_base'],
'url_param' => $_POST['kutrl_srv_custom_url_param'], '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))); $this->settings->put('kutrl_srv_custom', base64_encode(serialize($config)));
} }
@ -53,9 +53,9 @@ class customKutrlService extends kutrlService
'url_api' => '', 'url_api' => '',
'url_base' => '', 'url_base' => '',
'url_param' => '', '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)) { if (!is_array($config)) {
$config = []; $config = [];
} }

View File

@ -33,7 +33,7 @@ class defaultKutrlService extends kutrlService
'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2, 'url_min_len' => strlen(SHORTEN_SERVICE_BASE) + 2,
'url_param' => SHORTEN_SERVICE_PARAM, 'url_param' => SHORTEN_SERVICE_PARAM,
'url_encode' => SHORTEN_SERVICE_ENCODE 'url_encode' => SHORTEN_SERVICE_ENCODE,
]; ];
} }

View File

@ -23,7 +23,7 @@ class googlKutrlService extends kutrlService
private $url_api = 'https://www.googleapis.com/urlshortener/v1/url'; private $url_api = 'https://www.googleapis.com/urlshortener/v1/url';
private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL'; private $url_test = 'http://dotclear.jcdenis.com/go/kUtRL';
private $args = [ private $args = [
'key' => '' 'key' => '',
]; ];
private $headers = ['Content-Type: application/json']; private $headers = ['Content-Type: application/json'];

View File

@ -23,7 +23,7 @@ class isgdKutrlService extends kutrlService
'url_api' => 'http://is.gd/api.php', 'url_api' => 'http://is.gd/api.php',
'url_base' => 'http://is.gd/', 'url_base' => 'http://is.gd/',
'url_min_length' => 25 'url_min_length' => 25,
]; ];
public function testService() public function testService()

View File

@ -21,7 +21,7 @@ class localKutrlService extends kutrlService
'name' => 'kUtRL', 'name' => 'kUtRL',
'home' => 'https://github.com/JcDenis/kUtRL', 'home' => 'https://github.com/JcDenis/kUtRL',
'allow_custom_hash' => true 'allow_custom_hash' => true,
]; ];
protected function init() protected function init()
@ -29,7 +29,7 @@ class localKutrlService extends kutrlService
$protocols = (string) $this->settings->kutrl_srv_local_protocols; $protocols = (string) $this->settings->kutrl_srv_local_protocols;
$this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $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; $this->config['url_min_len'] = strlen($this->url_base) + 2;
} }
@ -62,7 +62,7 @@ class localKutrlService extends kutrlService
'</label></p>' . '</label></p>' .
'<p class="area" id="style-area"><label for="_style">' . __('CSS:') . '</label>' . '<p class="area" id="style-area"><label for="_style">' . __('CSS:') . '</label>' .
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') .
'</p>' . '</p>' .
'<p class="form-note">' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '</p>' . '<p class="form-note">' . __('You can add here special cascading style sheet. Body of page has class "dc-kutrl" and widgets have class "shortenkutrlwidget" and "rankkutrlwidget".') . '</p>' .
@ -221,7 +221,6 @@ class localKutrlService extends kutrlService
return false; return false;
} }
if (!$rs->url) { //previously removed url if (!$rs->url) { //previously removed url
return false; return false;
} }
$this->log->counter($rs->id, 'up'); $this->log->counter($rs->id, 'up');

View File

@ -23,7 +23,7 @@ class shorttoKutrlService extends kutrlService
'url_api' => 'http://short.to/s.txt', 'url_api' => 'http://short.to/s.txt',
'url_base' => 'http://short.to/', 'url_base' => 'http://short.to/',
'url_min_len' => 25 'url_min_len' => 25,
]; ];
public function testService() public function testService()

View File

@ -23,14 +23,14 @@ class suprKutrlService extends kutrlService
'url_api' => 'http://su.pr/api/', 'url_api' => 'http://su.pr/api/',
'url_base' => 'http://su.pr/', 'url_base' => 'http://su.pr/',
'url_min_len' => 23 'url_min_len' => 23,
]; ];
private $args = [ private $args = [
'version' => '1.0', 'version' => '1.0',
'format' => 'xml', 'format' => 'xml',
'login' => '', 'login' => '',
'apiKey' => '' 'apiKey' => '',
]; ];
protected function init() protected function init()

View File

@ -23,12 +23,12 @@ class trimKutrlService extends kutrlService
'url_api' => 'http://api.tr.im/v1/', 'url_api' => 'http://api.tr.im/v1/',
'url_base' => 'http://tr.im/', 'url_base' => 'http://tr.im/',
'url_min_len' => 25 'url_min_len' => 25,
]; ];
private $args = [ private $args = [
'username' => '', 'username' => '',
'password' => '' 'password' => '',
]; ];
private $api_rate_time = 0; private $api_rate_time = 0;

View File

@ -19,14 +19,14 @@ class yourlsKutrlService extends kutrlService
protected $config = [ protected $config = [
'id' => 'yourls', 'id' => 'yourls',
'name' => 'YOURLS', 'name' => 'YOURLS',
'home' => 'http://yourls.org' 'home' => 'http://yourls.org',
]; ];
private $args = [ private $args = [
'username' => '', 'username' => '',
'password' => '', 'password' => '',
'format' => 'xml', 'format' => 'xml',
'action' => 'shorturl' 'action' => 'shorturl',
]; ];
protected function init() protected function init()

View File

@ -15,7 +15,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
} }
# Check user perms # Check user perms
dcPage::check('admin'); dcPage::check(dcAuth::PERMISSION_ADMIN);
$header = ''; $header = '';
$part = $_REQUEST['part'] ?? 'links'; $part = $_REQUEST['part'] ?? 'links';
@ -23,14 +23,14 @@ $action = $_POST['action'] ?? '';
# link creation # link creation
if ($part == 'link') { if ($part == 'link') {
$kut = kutrl::quickPlace('admin'); $kut = kUtRL::quickPlace('admin');
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
if (null === $kut) { if (null === $kut) {
throw new Exception('Unknow service'); 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']; $hash = empty($_POST['custom']) ? null : $_POST['custom'];
if (empty($url)) { if (empty($url)) {
@ -64,7 +64,7 @@ if ($part == 'link') {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
dcPage::addSuccessNotice(sprintf( dcAdminNotices::addSuccessNotice(sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
'<strong>' . html::escapeHTML($url) . '</strong>', '<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
@ -80,7 +80,7 @@ if ($part == 'link') {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
dcPage::addSuccessNotice(sprintf( dcAdminNotices::addSuccessNotice(sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
'<strong>' . html::escapeHTML($url) . '</strong>', '<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
@ -88,28 +88,28 @@ if ($part == 'link') {
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
$core->callBehavior('adminAfterKutrlCreate', $core, $rs, __('New short URL')); dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, __('New short URL'));
} }
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
# links # links
} else { } else {
$services_combo = []; $services_combo = [];
foreach (kutrl::getServices($core) as $service_id => $service) { foreach (kUtRL::getServices() as $service_id => $service) {
$o = new $service($core); $o = new $service();
$services_combo[__($o->name)] = $o->id; $services_combo[__($o->name)] = $o->id;
} }
$ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo);
$lst_services_combo = array_merge(['-' => ''], $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('part', 'links');
$kUtRL_filter->add(dcAdminFilters::getPageFilter()); $kUtRL_filter->add(dcAdminFilters::getPageFilter());
$kUtRL_filter->add(dcAdminFilters::getSelectFilter( $kUtRL_filter->add(dcAdminFilters::getSelectFilter(
@ -124,12 +124,12 @@ if ($part == 'link') {
try { try {
$list_all = $log->getLogs($params); $list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0); $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) { } 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')); dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js'));
if (!empty($_POST['deletelinks'])) { if (!empty($_POST['deletelinks'])) {
@ -139,20 +139,20 @@ if ($part == 'link') {
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
continue; continue;
} }
if (null === ($o = kutrl::quickService($rs->kut_type))) { if (null === ($o = kUtRL::quickService($rs->kut_type))) {
continue; continue;
} }
$o->remove($rs->kut_url); $o->remove($rs->kut_url);
} }
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Links successfully deleted') __('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) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
} }
@ -168,8 +168,8 @@ if ($part == 'link') {
echo echo
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Links shortener') => $core->adminurl->get('admin.plugin.kUtRL'), __('Links shortener') => dcCore::app()->adminurl->get('admin.plugin.kUtRL'),
__('New link') => '' __('New link') => '',
]) . ]) .
dcPage::notices(); dcPage::notices();
@ -179,7 +179,7 @@ if ($part == 'link') {
echo ' echo '
<div class="fieldset"> <div class="fieldset">
<h4>' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '</h4> <h4>' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '</h4>
<form id="create-link" method="post" action="' . $core->adminurl->get('admin.plugin.kUtRL') . '"> <form id="create-link" method="post" action="' . dcCore::app()->adminurl->get('admin.plugin.kUtRL') . '">
<p><label for="str">' . __('Long link:') . '</label>' . <p><label for="str">' . __('Long link:') . '</label>' .
form::field('str', 100, 255, '') . '</p>'; form::field('str', 100, 255, '') . '</p>';
@ -199,7 +199,7 @@ if ($part == 'link') {
echo ' echo '
<p><input type="submit" name="save" value="' . __('Save') . '" />' . <p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce() . dcCore::app()->formNonce() .
form::hidden(['part'], 'link') . ' form::hidden(['part'], 'link') . '
</p></div> </p></div>
</form>'; </form>';
@ -208,12 +208,12 @@ if ($part == 'link') {
echo echo
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Links shortener') => '' __('Links shortener') => '',
]) . ]) .
dcPage::notices() . dcPage::notices() .
'<p class="top-add"><a class="button add" href="' . '<p class="top-add"><a class="button add" href="' .
$core->adminurl->get('admin.plugin.kUtRL', ['part' => 'link']) . dcCore::app()->adminurl->get('admin.plugin.kUtRL', ['part' => 'link']) .
'">' . __('New Link') . '</a></p>'; '">' . __('New Link') . '</a></p>';
$kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links')); $kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links'));
@ -221,7 +221,7 @@ if ($part == 'link') {
$list_current->display( $list_current->display(
$kUtRL_filter->value('page'), $kUtRL_filter->value('page'),
$kUtRL_filter->nb, $kUtRL_filter->nb,
'<form action="' . $core->adminurl->get('admin.plugin.kUtRL') . '" method="post" id="form-entries"> '<form action="' . dcCore::app()->adminurl->get('admin.plugin.kUtRL') . '" method="post" id="form-entries">
%s %s
@ -231,8 +231,8 @@ if ($part == 'link') {
</div> </div>
<p class="col right"> <p class="col right">
<input id="do-action" type="submit" value="' . __('Delete selected short links') . '" /></p>' . <input id="do-action" type="submit" value="' . __('Delete selected short links') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) .
$core->formNonce() . ' dcCore::app()->formNonce() . '
</p> </p>
</div> </div>
</form>', </form>',

View File

@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) {
return; return;
} }
$__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html'; dcCore::app()->resources['help']['kUtRL'] = __DIR__ . '/help/help.html';

View File

@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) {
return; return;
} }
$__resources['help']['kUtRL'] = dirname(__FILE__) . '/help/help.html'; dcCore::app()->resources['help']['kUtRL'] = __DIR__ . '/help/help.html';