prepare to DC 2.24

This commit is contained in:
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;
}
$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();
$kut->hash($posts->getURL());
}
if ($action == 'kutrl_create') {
$kut->hash($url);
dcAdminNotices::addSuccessNotice(__('Posts short links have been created.'));
$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
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();

View File

@ -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 = '<img src="images/check-on.png" alt="ok" />';
$img_red = '<img src="images/check-off.png" alt="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') . '</label></p>
<h5>' . __('Default services') . '</h5>
<p><label>';
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;
}
}
@ -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><label>';
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;
}
}
@ -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><label>';
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;
}
}
@ -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><label>';
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;
}
}
@ -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>
';
foreach (kutrl::getServices($core) as $service_id => $service) {
$o = new $service($core);
foreach (kUtRL::getServices() as $service_id => $service) {
$o = new $service();
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);
}
} 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();
}

View File

@ -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',
'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'
'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml',
]
);

View File

@ -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;

View File

@ -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';
}

View File

@ -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) {
@ -67,15 +66,15 @@ class urlKutrl extends dcUrlHandlers
}
$args = $m[3] ?? '';
$_ctx->kutrl_msg = '';
$_ctx->kutrl_hmf = hmfKutrl::create();
$_ctx->kutrl_hmfp = hmfKutrl::protect($_ctx->kutrl_hmf);
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']) : '?';
@ -137,44 +135,44 @@ class urlKutrl extends dcUrlHandlers
if (!$err) {
if ($hmf != $hmfu) {
$err = true;
$_ctx->kutrl_msg = __('Failed to verify protected field.');
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.');
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.');
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.');
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.');
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.');
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.');
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),
'<a href="' . $new_url . '">' . $new_url . '</a>'
@ -194,27 +192,27 @@ class urlKutrl extends dcUrlHandlers
if (!$err) {
if (false === ($rs = $kut->hash($url))) {
$err = true;
$_ctx->kutrl_msg = __('Failed to create short link.');
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),
'<a href="' . $new_url . '">' . $new_url . '</a>'
);
$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 '<?php $GLOBALS["disable_kutrl"] = true; ?>';
@ -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 '<?php $GLOBALS["disable_kutrl"] = false; ?>';
@ -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<!-- CSS for kUtRL --> \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 '<?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)
@ -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 '<?php echo $_ctx->kutrl_msg; ?>';
return '<?php echo dcCore::app()->ctx->kutrl_msg; ?>';
}
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)
{
return
'<input type="hidden" name="hmfp" id="hmfp" value="<?php echo $_ctx->kutrl_hmfp; ?>" />' .
'<?php echo $core->formNonce(); ?>';
'<input type="hidden" name="hmfp" id="hmfp" value="<?php echo dcCore::app()->ctx->kutrl_hmfp; ?>" />' .
'<?php echo dcCore::app()->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
"<?php \n" .
# Preview
"if (\$_ctx->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" .

View File

@ -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)) : '') .
'<form name="shortenkutrlwidget" method="post" action="' .
$core->blog->url . $core->url->getBase('kutrl') . '">' .
dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '">' .
'<p><label>' .
__('Long link:') . '<br />' .
form::field('longurl', 20, 255, '') .
@ -144,7 +143,7 @@ class widgetKutrl
'</label></p>' .
'<p><input class="submit" type="submit" name="submiturl" value="' . __('Shorten') . '" />' .
form::hidden('hmfp', $hmfp) .
$core->formNonce() .
dcCore::app()->formNonce() .
'</p>' .
'</form>'
);
@ -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 = '<span class="rankkutrl-rank">' . $i . '</span>';
$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 .= '<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(
['%rank%', '%hash%', '%url%', '%count%', '%counttext%'],

View File

@ -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,7 +28,7 @@ class kUtRL
$services = [];
foreach ($list as $k => $callback) {
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;
} 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)) {

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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 = __('&#171; 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' => '<th colspan="2" class="first">' . __('Link') . '</th>',
'kut_hash' => '<th scope="col">' . __('Hash') . '</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);
$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 = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
}
@ -117,11 +115,11 @@ class kutrlLinkslist
$hash .
'</td>',
'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>',
'kut_service' => '<td class="nowrap">' .
$type .
'</td>'
'</td>',
];
$cols = new ArrayObject($cols);

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -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()

View File

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

View File

@ -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 = [];
}

View File

@ -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,
];
}

View File

@ -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'];

View File

@ -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()

View File

@ -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
'</label></p>' .
'<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 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;
}
if (!$rs->url) { //previously removed url
return false;
}
$this->log->counter($rs->id, 'up');

View File

@ -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()

View File

@ -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()

View File

@ -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;

View File

@ -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()

View File

@ -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'),
'<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>'
@ -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'),
'<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>'
@ -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
} 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 '
<div class="fieldset">
<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>' .
form::field('str', 100, 255, '') . '</p>';
@ -199,7 +199,7 @@ if ($part == 'link') {
echo '
<p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce() .
dcCore::app()->formNonce() .
form::hidden(['part'], 'link') . '
</p></div>
</form>';
@ -208,12 +208,12 @@ if ($part == 'link') {
echo
dcPage::breadcrumb([
__('Plugins') => '',
__('Links shortener') => ''
__('Links shortener') => '',
]) .
dcPage::notices() .
'<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>';
$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,
'<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
@ -231,8 +231,8 @@ if ($part == 'link') {
</div>
<p class="col right">
<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))) .
$core->formNonce() . '
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) .
dcCore::app()->formNonce() . '
</p>
</div>
</form>',

View File

@ -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';

View File

@ -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';